Python: procedures and functions
Big programs are built from small, named blocks of code called subprograms. Write a block once, then use it as often as you like.
Defining a subprogram
def greet(name):
print("Hi " + name)
greet("Zara")
Output: Hi Zara
name is a parameter: a value passed in when the subprogram is called. "Zara" is the argument.
Procedures and functions
A function sends a value back with return.
def area(width, height):
return width * height
print(area(4, 5))
Output: 20
Why use subprograms?
Decomposition: each subprogram solves one small part of the problem.
Testing: you can test each part on its own.
Teamwork: different people can write different subprograms.
Programs built this way are called modular.
What does this print?
def double(n):
return n * 2
x = double(3)
print(double(x))
- double(3) returns 6, so x = 6.
- double(6) returns 12.
Answer: 12
Define subprograms with def. Parameters receive values. A function returns a value; a procedure does not. Subprograms make code reusable, easier to test and easier to share in a team.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- Function
- A subprogram that carries out a task and returns a value to the code that called it.
- Procedure
- A subprogram that carries out a task but does not return a value.
- NOT
- A Boolean operator that flips its input: True becomes False and False becomes True.
- Output
- Information sent out from a computer, for example to a screen, speaker or printer.
- Parameter
- A variable in a subprogram's definition that receives a value when the subprogram is called.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
What does this print?
def area(width, height):
return width * height
print(area(5, 6))Show the answer
Answer: 30
5 × 6 = 30.
What does this print?
def double(n):
return n * 2
x = double(4)
print(double(x))Show the answer
Answer: 16
double(4) = 8, then double(8) = 16.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Facts checked against the sources below, 27 October 2026. Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.