February 2006
Intermediate to advanced
648 pages
14h 53m
English
Functions are defined with the def statement:
def add(x,y):
return x+yYou invoke a function by writing the function name followed by a tuple of function arguments, such as a = add(3,4). The order and number of arguments must match those given in the function definition. If a mismatch exists, a TypeError exception is raised.
You can attach default arguments to function parameters by assigning values in the function definition. For example:
def foo(x,y,z = 42):
When a function defines a parameter with a default value, that parameter and all the parameters that follow are optional. If values are not assigned to all the optional parameters in the function definition, a SyntaxError exception is raised.
Default parameter values are always ...
Read now
Unlock full access