September 2026
1051 pages
35h 4m
English
Besides the positional arguments used so far, there is another way to pass arguments in Python. Such arguments are called keyword arguments. This is an alternative technique of passing arguments when calling a function. Nothing changes in the function definition. To do this, let's consider the sum function from the previous section:
>>> def my_sum(a, b, c=0, d=0):... return a + b + c + d
This function can also be called as follows:
>>> my_sum(d=1, b=3, c=2, a=1)7
For this purpose, the parameters are set to the desired value in the function call, as with an assignment. Because the respective parameter name must be specified in the function call, the assignment is unique under all circumstances. This allows the programmer ...
Read now
Unlock full access