Positional and Keyword Arguments

Positional Arguments:

  • Positional arguments are assigned to function parameters based on their order in the argument list.
  • The function mortgage_rate calculates and returns the monthly mortgage payment.
  • Parameters: amount, rate, and term.

Keyword Arguments:

  • Python allows calling functions using keyword arguments.
  • Keyword arguments are specified by parameter name, not position.
  • Example: monthly_payment = mortgage_rate(rate=0.06, term=20, amount=350000)
  • Combining Positional and Keyword Arguments:
    • Functions can be called with a mix of positional and keyword arguments.
    • However, positional arguments must come before keyword arguments.
    • Example: monthly_payment = mortgage_rate(35000, term=20, rate=0.06)