The return statement is used to return from a function i.e. break out of the function. We can optionally return a value from the function as well.
Example 7.7. Using the return statement
#!/usr/bin/python # Filename : return.py def max(x, y): if x > y: return x else: return y print max(2, 3)
The max function returns the maximum of the parameters i.e. numbers supplied to the function. When it determines the maximum, it returns that value.
Note that a return statement without a value is equivalent to return None. None is a special value in Python which presents nothingness. For example, it is used to indicate that a variable has no value if the variable has a value of None.
Every function implicitly contains a return None statement. You can see this by running print someFunction() where the function someFunction does not use the return statement such as
def someFunction(): pass
The pass statement is used in Python to indicate an empty block of statements.