May 2019
Beginner
528 pages
29h 51m
English
When defining a function, you can specify that a parameter has a default parameter value. When calling the function, if you omit the argument for a parameter with a default parameter value, the default value for that parameter is automatically passed. Let’s define a function rectangle_area with default parameter values:
In [1]: def rectangle_area(length=2, width=3):...: """Return a rectangle's area."""...: return length * width...:
You specify a default parameter value by following a parameter’s name with an = and a value—in this case, the default parameter values are 2 and 3 for length and width, respectively. Any parameters with default parameter values must appear in the parameter list to the right of parameters ...
Read now
Unlock full access