1, * 运算符用于分解可变参数,例如,在函数中使用*运算符接受多个参数。
def example(*args):
return list(map(lambda x:x*2,args))
example('de','a','b','c')

2.当参数已经在列表或元组中但需要为需要单独位置参数的函数调用解包。
example(['d','f','g'])
example(*['d','f','g'])

也可用于元组
example(*('s','q','w'))

3.**运算符用于在函数中接受字典类型的参数
def demo(**args):
for key in args:
print(key,":",args[key])
demo(s='s',d='d')
arg={'s':'s','d':'d'}
demo(**arg)

网友评论