-
python函数参数前面单星号(*)和双星号(**)的区别
-
*将任意个数的参数以元组传入函数中
>>> def foo(param1, *param2): print param1 print param2 >>> foo(1,2,3,4,5) 1 (2, 3, 4, 5)
-
此外,单星号的另一个用法是解压参数列表:
>>> def foo(bar, lee): print bar, lee >>> l = [1, 2] >>> foo(*l) 1 2
-
双星号():kwargs
将参数以字典的形式导入>>> def bar(param1, **param2): print param1 print param2 >>> bar(1,a=2,b=3) 1 {'a': 2, 'b': 3}
-