← Back to blog Python

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

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 →

Practise functions with feedback

Solve auto-marked challenges on functions and procedures.

Try the challenges →