Default Values for Parameters

Learn about parameter defaults and usage in Python functions.

If we want to make a parameter’s value optional, we can specify a default value. Some other languages (Java, for example) require a second method with a different set of parameters. In Python, we define a single method; we can provide a default value for a parameter using an equals sign. If the calling code does not supply an argument value for the parameter, it will be assigned the given default value. This means calling code can still choose to override the default by passing in a different value. If a value of None is used as the default for optional parameter values, the typing module lets us describe this using the Optional type hint.

Here’s a function definition with default parameter definitions:

Get hands-on with 1400+ tech skills courses.