#过程:就是没有返回值的函数
def test01():
msg = 'hello The little green frog'
print(msg)
def test02():
msg = 'hello WuDaLang'
print(msg)
return msg
def test03():
msg = 'hello WuDaLang'
print(msg)
return msg, (1,2,3), {"name":"ly"}
t1 = test01()
t2 = test02()
t3 = test03()
print(t1)
print(t2)
print(t3) #实际上只返回一个值,就一个元组
"""
总结:
返回值数=0;返回None
返回值数=1;返回object
返回值数>1;返回tuple
"""
def calc(x,y): # 形参
res = x**y
return res
c = calc(2,3) #实参
print(c)
a = 10
b = 10
d= calc(a,b)
print(d)
def test(x,y,z):
print(x)
print(y)
print(z)
test(1,2,3) #位置参数
test(x=1,y=3,z=2) #关键字参数
test(1,3,z=2) #位置参数必须在关键字参数左边
def handle(x,type='mysql'):
print(x)
print(type)
handle('hello')
handle('hello',type='sqllite')
handle('hello','sqllite')
#参数组**字典 *列表
def test(x,*args):
print(x)
print(args)
print(args[0])
test(1,2,3,4,5,6)
test(1,{'name':'alex'})
test(1,[x,y,z])
test(1,*[x,y,z]) #遍历一遍
def test(x,**kwargs):
print(x)
print(kwargs)
test(1,y=2,z=3) # 字典
# 一起使用,*args必须在前面,不能违背大原则
def test(x,*args,**kwargs):
print(x)
print(args)
print(kwargs)
test(1,2,k=2)
def test(x,*args,**kwargs):
print(x)
print(args,args[-1])
print(kwargs,kwargs.get('y')) # 字典获取元素
test(1,1,2,1,1,11,x=1,y=2,z=3) # 报错
test(1,1,1,2,4,11,y=2,z=3)
test(1,*[1,2,3],**{'y':1})