Are you talking about variable length argument lists? If so, take a look at *args
, **kwargs
.
See this Basic Guide and How to use *args and **kwargs in Python
Two short examples from [1]:
Using *args
:
def test_var_args(farg, *args):
print "formal arg:", farg
for arg in args:
print "another arg:", arg
test_var_args(1, "two", 3)
Results:
formal arg: 1
another arg: two
another arg: 3
and using **kwargs
(keyword arguments):
def test_var_kwargs(farg, **kwargs):
print "formal arg:", farg
for key in kwargs:
print "another keyword arg: %s: %s" % (key, kwargs[key])
test_var_kwargs(farg=1, myarg2="two", myarg3=3)
Results:
formal arg: 1
another keyword arg: myarg2: two
another keyword arg: myarg3: 3
Quoting from this SO question What do *args and **kwargs mean?:
Putting *args and/or **kwargs as the last items in your function
definition’s argument list allows that function to accept an arbitrary
number of anonymous and/or keyword arguments.