简体   繁体   English

python函数是否可以使用未指定数量的参数?

[英]Can there be python functions that take unspecified number of arguments?

Can there be python functions that take unspecified number of arguments such as python函数是否可以使用未指定数量的参数,例如

myfunc(a, b, c)

myfunc(a, b, c, d, e)

where both will work? 两者都将在哪里工作?

myfunc(*args, **kw) myfunc(* args,** kw)

*args - takes N number of arguments * args-接受N个参数

**kw - takes dictionary (unspecified depth) ** 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM