函数的分类
def func1 ( ) :
print ( "func1()" )
return
print ( func1( ) )
def func2 ( ) :
print ( "func2()" )
return "哈哈" , 100
a = func2( )
print ( a)
def func3 ( x, y) :
res = x** y
print ( "x ** y = " , res)
func3( 2 , 5 )
def func4 ( a, b, c) :
"""返回最大的数"""
if a > b:
if a > c:
return a
return c
else :
if b > c:
return b
return c
print ( func4( 2 , 3 , 44 ) )
print ( func4( 2111 , 3 , 44 ) )
参数的分类
def show ( name, age, addr) :
age += 1
print ( "姓名 : {}. 年龄: {}, 地址:{}" . format ( name, age, addr) )
print ( f"姓名 : {name}. 年龄: {age}, 地址:{addr}" )
show( "JiaZhen" , 17 , "沈阳市" )
show( addr= "铁岭的" , name= "JiaZhenLi" , age= 19 )
show( addr= "铁岭的" , name= "JiaZhenLi" , age= 19 )
show( "JiaZhenLi" , addr= "铁岭的" , age= 22 )
print ( "+++++++++++++++++++++++++++++++++++++++++" )
def show2 ( name, addr, age= 18 ) :
age += 1
print ( "姓名 : {}. 年龄: {}, 地址:{}" . format ( name, age, addr) )
print ( f"姓名 : {name}. 年龄: {age}, 地址:{addr}" )
show2( "JiaZhen" , "沈阳市" )
show2( "JiaZhen" , "沈阳市" , 30 )
列表的基本操作
name1 = "张三"
stu_list = [ name1, "李四" , "王五" , "赵六" , "田七" , 111 , 99.9 , [ 22 , 22 ] ]
print ( stu_list)
print ( type ( stu_list) )
print ( stu_list[ 0 ] )
print ( stu_list[ 2 ] )
print ( stu_list. index( "李四" ) )
stu_list[ 5 ] = "刘能"
print ( stu_list)
stu_list. append( "谢广坤" )
stu_list. append( "谢广坤" )
stu_list. append( [ "谢永强" , "刘颖" ] )
print ( stu_list)
stu_list. insert( 1 , "宋晓峰" )
print ( stu_list)
stu_list. extend( [ "谢永强" , "刘颖" ] )
print ( stu_list)
del stu_list[ 0 ]
print ( stu_list)
stu_list. clear( )
print ( stu_list. pop( ) )
print ( stu_list. pop( 0 ) )
print ( stu_list)
stu_list. remove( "王五" )
print ( stu_list)
```
```python
from random import randint
li = [ ]
for i in range ( 10 ) :
li. append( i)
print ( li)
score_list = [ ]
for _ in range ( 10 ) :
score = randint( 40 , 100 )
score_list. append( score)
print ( score_list)
jige_list = [ ]
for score in score_list:
if score >= 60 :
jige_list. append( score)
print ( jige_list)
evenNum_list = [ ]
for mark in score_list:
if mark % 2 == 0 :
evenNum_list. append( mark)
print ( evenNum_list)
```
```python
from random import randint
score_list = [ ]
for _ in range ( 10 ) :
score = randint( 40 , 100 )
score_list. append( score)
print ( score_list)
def score_mean ( ls) :
total = 0
for score in ls:
total += score
return total/ len ( ls)
print ( score_mean( score_list) )
print ( sum ( score_list) / len ( score_list) )
```