how.wtf

What is double asterisk kwargs in Python

· Thomas Taylor

When developing in Python, it’s common to come across **kwargs.

What is the double asterisk (**) in Python?

If a function parameter explictly denotes the double asterisk:

1def foo(**kwargs):
2    print(kwargs)
3
4foo(bar="test", baz=5)

kwargs will represent a dictionary of the key word arguments given to the function.

NOTE: kwargs is a standard name that refers to “key word arguments”; however, any name may be used.

Output:

1{'bar': 'test', 'baz': 5}

#Python  

Reply to this post by email ↪