2019-08-03 python中 * 的作用

def sum(a, b, c):
    return a + b + c

a = [1, 2, 3]

# the * unpack a list 
print sum(*a)
>> 6
def sum(a, b, c):
    return a + b + c

a = {'a': 1, 'b': 2, 'c': 3}

# the ** unpack a dict 
print sum(**a)
>> 6

你可能感兴趣的:(2019-08-03 python中 * 的作用)