How to expand a list to function arguments in Python [duplicate]

It exists, but it’s hard to search for. I think most people call it the “splat” operator.

It’s in the documentation as “Unpacking argument lists“.

You’d use it like this for positional arguments:

values = [1, 2]
foo(*values)

There’s also one for dictionaries to call with named arguments:

d = {'a': 1, 'b': 2}
def foo(a, b):
    pass
foo(**d)

Leave a Comment