Python - use list as function parameters

Jonathan picture Jonathan · Feb 12, 2011 · Viewed 175.9k times · Source

How can I use a Python list (e.g. params = ['a',3.4,None]) as parameters to a function, e.g.:

def some_func(a_char,a_float,a_something):
   # do stuff

Answer

Neil Vass picture Neil Vass · Feb 12, 2011

You can do this using the splat operator:

some_func(*params)

This causes the function to receive each list item as a separate parameter. There's a description here: http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists