October 2018
Beginner to intermediate
466 pages
12h 2m
English
If we want to make an argument optional, rather than creating a second method with a different set of arguments, we can specify a default value in a single method, using an equals sign. If the calling code does not supply this argument, it will be assigned a default value. However, the calling code can still choose to override the default by passing in a different value. Often, a default value of None, or an empty string or list, is suitable.
Here's a function definition with default arguments:
def default_arguments(x, y, z, a="Some String", b=False):
pass
The first three arguments are still mandatory and must be passed by the calling code. The last two parameters have default arguments supplied.
There are several ways ...