arbitrary number of arguments in a function declaration

Steven Bethard steven.bethard at gmail.com
Sun Jan 2 20:30:22 CET 2005


rbt wrote:
> How do I set up a function so that it can take an arbitrary number of 
> arguments?

If you haven't already, you should check out the Tutorial:

http://docs.python.org/tut/node6.html#SECTION006730000000000000000

> How might I make this dynamic so 
> that it can handle any amount of expenses?
> 
> def tot_expenses(self, e0, e1, e2, e3):
>     pass

py> class C(object):
...     def tot_expenses(self, *expenses):
...         print expenses
...
py> C().tot_expenses(110, 24)
(110, 24)
py> C().tot_expenses(110, 24, 2, 56)
(110, 24, 2, 56)

Steve



More information about the Python-list mailing list