Default Arguments in Python

Default arguments enable specifying default values for function parameters.
In this example, term has a default value of 20 years if not provided explicitly.
  • In this case, the third argument in calls to function mortgage_rate is optional.
  • If omitted, parameter term will default to the value 20 (years) as shown.
  • If, on the other hand, a third argument is provided, the value passed replaces the default parameter value.

Providing Explicit Values:

monthly_payment = mortgage_rate(35000, 0.62, 30)  # term is explicitly set to 30

  • All positional arguments must come before any default arguments in a function definition.