def test(*numbers):
sum = 0
for i in numbers:
sum = sum + i
return sum
print(test(4, 5))
print(test(4, 5, 5))
l4 = [4, 5, 6]
print(test(*l4))
关键字参数在函数内部自动组装为一个dict
def test(name, age, **kw):
print('name:', name, 'age:', age, 'other:', kw)
test('jack', 18)
test('jackson', 18, city='beijing')
test('judy', 18, city='beijing', job='engineer')
extra = {
'city': 'Beijing', 'job': 'Engineer'}
test('jeacka', 18, **extra)
args是可变参数,args接收的是一个tuple
kw是关键字参数,kw接收的是一个dict