All courses › Programming with Python › Functions and return
Functions and return
A function is defined with def and can take parameters, often with default values. return ends the function and sends a value back to the caller. Without return, the function gives None.
returns the value of ; gets default if not supplied
Symbols
| parameters | ||
| default value for | ||
| the expression returned |
Example
def f(a, b=2): return a * b
f(3) uses the default: .
A function with no
Practise functions and data structures for free →
return statement always gives None, not 0 or an empty string.← List comprehension · Dictionary (dict) →
Part of Programming with Python: Functions and data structures.