函数不确定时候,使用可变参数,有2种方式*args和*kwargs,*args没有key值,*kwargs有key值,*args必须位于**kwargs之前 .
def test_args(first,*num):
print(first)
for x in num:
print(x)
test_args(True,[0],3,'a')
def test_kwargs(first,*num,**money):
print(first)
for a in num:
print(a)
for k,v in money.items():
print('key is %s,value is %s' % (k,v))
test_kwargs(1,2,3,aa=1,bb='c')
网友评论