是否可以有 python 函数接受未指定数量的参数,例如
myfunc(a, b, c)
myfunc(a, b, c, d, e)
两者都适用于哪些地方?
请您参考如下方法:
myfunc(*args, **kw)
*args - 接受 N 个参数
**kw - 获取字典(未指定深度)
In [1]: def myfunc(*args):
...: print args
...:
In [2]: myfunc(1)
(1,)
In [3]: myfunc(1,2,3,4,5)
(1, 2, 3, 4, 5)
