Passing a tuple to a function as multiple arguments

George Sakkis george.sakkis at gmail.com
Thu Sep 6 23:22:49 EDT 2007


On Sep 6, 11:02 pm, Ben Warren <bwar... at qstreams.com> wrote:
> Hello,
>
> Let's say I have a function with a variable number of arguments (please ignore syntax errors):
>
> def myfunc(a,b,c,d,...):
>
> and I have a tuple whose contents I want to pass to the function.  The number of elements in the tuple will not always be the same.
>
> T = A,B,C,D,...
>
> Is there a way that I can pass the contents of the tuple to the function without explicitly indexing the elements?

Yes:

myfunc(*T)

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


HTH,
George




More information about the Python-list mailing list