Python function arguments - a reminder
- Order of parameter
- Arguments with default values are optional (and come at the end of the definition)
- Number of arguments is know at the time of function definition. The only flexibility is provided by the optional arguments.
examples/advanced/function_arguments.py
def f(a, b = 42): print(a) print(b) f(23) # 23 # 42 f(19, 11) # 19 # 11 f(b=7, a=8) # 8 # 7 # f() # (runtime) TypeError: f() takes at least 1 argument (0 given) # f(1, 2, 3) # (runtime) TypeError: f() takes at most 2 arguments (3 given) # f(b=10, 23) # SyntaxError: non-keyword arg after keyword arg # def g(a=23, b): # pass # SyntaxError: non-default argument follows default argument