Several defaults, using names


Parameters with defaults must come at the end of the parameter declaration.

examples/functions/named_params_and_defaults.py
def f(a, b=2, c=3):
    print(a, b , c)

f(1)             # 1 2 3
f(1, b=0)        # 1 0 3
f(1, c=0)        # 1 2 0
f(1, c=0, b=5)   # 1 5 0

# f(b=0, 1)
# would generate:
# SyntaxError: non-keyword arg after keyword arg

f(b=0, a=1)      # 1 0 3

examples/functions/named_and_positional_bad.py
def f(a=2, b):
    print(a)
    print(b)

  File "examples/functions/named_and_positional_bad.py", line 2
    def f(a=2, b):
          ^
SyntaxError: non-default argument follows default argument

There can be several parameters with default values. They are all optional and can be given in any order after the positional arguments.