Expanding tuples into arguments Expanding tuples into arguments python python

Expanding tuples into arguments


myfun(*some_tuple) does exactly what you request. The * operator simply unpacks the tuple (or any iterable) and passes them as the positional arguments to the function. Read more about unpacking arguments.


Note that you can also expand part of argument list:

myfun(1, *("foo", "bar"))


Take a look at the Python tutorial section 4.7.3 and 4.7.4.It talks about passing tuples as arguments.

I would also consider using named parameters (and passing a dictionary) instead of using a tuple and passing a sequence. I find the use of positional arguments to be a bad practice when the positions are not intuitive or there are multiple parameters.