简体   繁体   中英

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

Can there be python functions that take unspecified number of arguments such as

myfunc(a, b, c)

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

where both will work?

myfunc(*args, **kw)

*args - takes N number of arguments

**kw - takes dictionary (unspecified depth)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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