This text is part of a Real Python tutorial by John Sturtz.
Default Parameters
If a parameter specified in a Python function definition has the form <name>=<value>
, then <value>
becomes a default value for that parameter. Parameters defined this way are referred to as default or optional parameters. An example of a function definition with default parameters is shown below:
Python
>>> def f(qty=6, item='bananas', price=1.74):
... print(f'{qty} {item} cost ${price:.2f}')
...
When this version of f()
is called, any argument that’s left out assumes its default value: