def func(**kwargs):
for key, value in kwargs.items():
# Is key always going to be a string?
# Could it have spaces?
pass
Two qu
Others have already covered the practical side of this, but I wondered if the documentation actually made any guarantees about keyword dictionaries' types.
The documentation on call semantics does not specifically say keyword arguments will have type str
in the dictionary.
This is all that the documentation says about the type of the value of keyword arguments passed to a parameter declared with **
:
a dictionary containing the excess keyword arguments (using the keywords as keys and the argument values as corresponding values), or a (new) empty dictionary
So, theoretically, it appears that the documentation allows you to recieve keyword arguments as bytes
, but this does not occur in any current implementation of Python 3.
(For Python 2, the same holds, but for unicode
instead of bytes
.)