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

742 views Asked by At

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?

1

There are 1 answers

1
avasal On BEST ANSWER

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)