December 2018
Beginner to intermediate
796 pages
19h 54m
English
Variable keyword arguments are very similar to variable positional arguments. The only difference is the syntax (** instead of *) and that they are collected in a dictionary. Collection and unpacking work in the same way, so let's look at an example:
# arguments.variable.keyword.pydef func(**kwargs): print(kwargs)# All calls equivalent. They print: {'a': 1, 'b': 42}func(a=1, b=42)func(**{'a': 1, 'b': 42})func(**dict(a=1, b=42))
All the calls are equivalent in the preceding example. You can see that adding a ** in front of the parameter name in the function definition tells Python to use that name to collect a variable number of keyword parameters. On the other hand, when we call the function, we can either pass ...
Read now
Unlock full access