1

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?

alwbtc
  • 28,057
  • 62
  • 134
  • 188
  • 6
    I'm not going to vote this down, but I suggest your life will be easier if you try to resolve these sorts of basic questions yourself, and find a tutorial/reference that you like to use to find this sort of basic information. – Marcin Jun 01 '12 at 10:22

1 Answers1

7

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)
avasal
  • 14,350
  • 4
  • 31
  • 47
  • 4
    A reference to the Python tutorial would be useful here, maybe something like: Have a look at the Python documentation on [defining functions](http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions). In particular, see the sections [arbitrary argument lists](http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists) and [unpacking argument lists](http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists). – Chris Jun 01 '12 at 10:48