###################################P42
def myfunc(name,times):
for i in range(int(times)):
print('I love FishC')
print(f'I love {name}')
pass
name='Python'
times=1
myfunc(name,times)
def div(x,y):
if y != 0 and type(x) ==int and type(y) ==int :
z= x/y
return round(z,2)
else:
return '输入不正确'
print(div('as',0))
###################################P43
def myfunc(s,vt,o):
return ''.join((o,vt,s))
print(myfunc(o='我',vt='打',s='小甲鱼'))
def myfunc(s,vt,o='小甲鱼'):
return ''.join((o,vt,s))
print(myfunc(s='香蕉',vt='吃'))
def myfunc(vt,s='苹果',o='小甲鱼'):
return ''.join((o,vt,s))
print(myfunc(vt='吃'))
print(abs(-1.5))
print(sum([1,2,3],4))
def abc(a,/,b,c):
print(a,b,c)
abc(3,b=2,c=1)
def abc(a,*,b,c):
print(a,b,c)
abc(1,b=2,c=4)
###############################################P44
def myfunc(*args):
print(f'有{len(args)}个参数')
print(f'第二个参数是:{args[1]}')
myfunc('小甲鱼','不二如是')
myfunc(1,2,3,4,5,6)
def myfunc():
return 1, 2 ,3
print(myfunc())
def myfunc(*args):
return args
print(myfunc(1,2,3,4))
def myfunc(*args,a,b):
return args,a,b
print(myfunc(1,2,3,4,a=5,b=6))
def abc(a,*,b,c):
print(a,b,c)
abc(1,b=2,c=3)
def myfunc(**kwargs):
return (kwargs)
print(myfunc(a=1,b=2,c=3))
def myfunc(a,*b,**c):
print (a,b,c)
myfunc(1,2,3,4,x=5,y=6)
args=(1,2,3,4)
def myfunc(a,b,c,d):
print(a,b,c,d)
myfunc(*args)
###############################################P45
def myfunc():
x=520
print(x)
myfunc()
x=880
def myfunc(x):
print('sss',x)
myfunc(x)
print('aaa',x)
def myfunc():
global x
x=520
print(x)
myfunc()
def funa():
x=520
def funb():
nonlocal x
x=880
print('IN FUNB,x=',x)
funb()
print('IN FUNA,x=', x)
funa()