To pass the elements of a list or tuple as arguments in a function, use this line of code (substituting your function name and list or tuple name):
The following code defines and calls a function, passing a list as its argument, using the * operator:
>>> def func with three args(a, b, c): ... print "the arguments are:", a, b, c
>>> weapons = ['fear', 'surprise', 'ruthless efficiency'] >>> func with three args(*weapons)
the arguments are: fear surprise ruthless efficiency
Was this article helpful?