Python Functions Explained Simply
June 19, 2026
A function is a named, reusable block of code. Functions keep programs tidy, avoid repetition, and make your code easier to read — all things examiners reward. This guide explains how to write and use them in Python.
Defining a function
def greet():
print("Hello!")
greet() # calls the function
Parameters: passing in data
Parameters let you give a function information to work with:
def greet(name):
print("Hello, " + name)
greet("Alice")
Return values: getting data back
Use return to send a result back to wherever the function was called:
def add(a, b):
return a + b
total = add(3, 4)
print(total) # 7
Why functions matter
- Reuse: write the code once, call it many times.
- Readability: a well-named function explains what code does.
- Decomposition: breaking a big problem into small functions is a key exam skill.
Functions vs procedures
In exam terms, a function returns a value, while a procedure just performs an action (like printing) without returning anything. In Python both are written with def — the difference is whether you use return.
Open the free online Python IDE and try writing a function that returns the area of a rectangle given its width and height. Then check your understanding with our coding challenges.
Try writing your own functions.
Open our free Python IDE and run these examples.
Open the Python IDE →