*args and **kwargs

Applies to: python

*args collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dict, letting a function accept a variable number of inputs. The same syntax unpacks a sequence/dict into arguments at a call.

def f(*args, **kwargs):
    return sum(args)        # args is a tuple
f(1, 2, 3)                  # 6
f(*[1, 2, 3])               # unpack a list into arguments

See also: function, parameter