How can I explode a tuple so that it can be passed as a parameter list?

froadie picture froadie · Jul 7, 2010 · Viewed 13.3k times · Source

Let's say I have a method definition like this:

def myMethod(a, b, c, d, e)

Then, I have a variable and a tuple like this:

myVariable = 1
myTuple = (2, 3, 4, 5)

Is there a way I can pass explode the tuple so that I can pass its members as parameters? Something like this (although I know this won't work as the entire tuple is considered the second parameter):

myMethod(myVariable, myTuple)

I'd like to avoid referencing each tuple member individually if possible...

Answer

unutbu picture unutbu · Jul 7, 2010

You are looking for the argument unpacking operator *:

myMethod(myVariable, *myTuple)