Add before parameter *
Number , It means that the number of parameters is more than one , With an asterisk *
The parameter passed in by the function of parameter is stored as a tuple (tuple), Take two *
The sign indicates the dictionary (dict)
for example :
def exam0(par0, *par1):
print(par0)
print(par1)
exam1(1,2,3,4)
# 1
# (2,3,4)
def exam1(par0, **par1):
print par0
print par1
exam2(1,a=2,b=3)
# 1
# {a:2, b:3}
*
No, No decompression
parameter list def exam3(par0, par1):
print(par0, par1)
args = [1, 2]
exam3(*args)
# 1 2
*
and **
def exam4(a, b=10, *args, **kwargs):
print(a)
print(b)
print(args)
print(kwargs)
exam4(1, 2, 3, 4, e=5, f=6, g=7)
# 1
# 2
# 3 4
# {'e': 5, 'g': 7, 'f': 6}