Home / Python / Reusable code

Functions

A function is a named, reusable block. def defines it, parameters take input, and return sends a result back. When functions and data belong together, group them in classes. Handle failures with errors.

def area(w, h):
    return w * h

print(area(3, 4))

Test yourself on this