Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有 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)