原文链接:https://www.cnblogs.com/omg-hxy/p/9081177.html
加“*”时,函数可接受任意多个参数,全部放入一个元祖中
加“**”时,函数接受参数时,返回为字典
def test(*args, **kwargs):
print(args)
print(kwargs)
print(type(args))
print(type(kwargs))
print(args[1])
print(kwargs['a'])
if __name__ == "__main__":
test(1, [2, 3], a = 1, b = 2)
输出:
(1, [2, 3])
{‘a’: 1, ‘b’: 2}
<class ‘tuple’>
<class ‘dict’>
[2, 3]
1