Python arguments as a dictionary
Use a single argument prefixed with **
.
>>> def foo(**args):
... print(args)
...
>>> foo(a=1, b=2)
{'a': 1, 'b': 2}
For non-keyworded arguments, use a single *
, and for keyworded arguments, use a **
.
For example:
def test(*args, **kwargs):
print args
print kwargs
>>test(1, 2, a=3, b=4)
(1, 2)
{'a': 3, 'b': 4}
Non-keyworded arguments would be unpacked to a tuple and keyworded arguments would be unpacked to a dictionary. Unpacking Argument Lists