Python: Function

By Xah Lee. Date: . Last updated: .

Define Function

Here's a example of defining a function.

def ff(x, y):
    """ff(x, y) returns x+y."""
    return x + y

print(ff(3, 4))
# 7

A string immediately following the function def line is the function's documentation.

Return is Optional

return is optional. If a function does not contain return statement, it returns None.