Course Content
Mastering Python: Annotations, Errors and Environment
Mastering Python: Annotations, Errors and Environment
Arbitrary Keyword Arguments (**kwargs)
Arbitrary Keyword Arguments (**kwargs
) are arbitrary arguments with name. Syntax of the keyword argument (keyword=argument
). The **kwargs
syntax allows us to pass a different number of named arguments.
In the example above, we pass the named arguments (first=11
and other) to the some_function()
.
The taken kwargs
is a dict
(dictionary) where:
- keys are taken keywords in the
str
type. - values are values of these keywords.
key (keyword) | value |
first | 11 |
second | 22 |
some | 33 |
The operations with keywords are regular dict
operations. You can use the keys()
dictionary method to get all taken keywords and use the items()
to get the key-value pairs:
Everything was clear?