Why Functions?

You already use functions every day — print() is a function! So is input(), len(), and range(). But what if you could create your own functions that do exactly what you need?

Functions are reusable blocks of code with a name. You define them once, and then you can call (run) them whenever you like — as many times as you want.

Real-world analogy Think of a recipe. You write it down once, and then every time you want that dish, you follow the same steps. You do not rewrite the recipe each time — you just say “make the pasta bake” and follow the instructions you already have. A function works in exactly the same way: you define it once, then call it whenever you want that piece of code to run.

What you will learn

Did you know? The concept of functions in programming was inspired by functions in mathematics. In maths, you write f(x) = x² to define a rule that takes an input and produces an output. Programming functions work the same way — they take inputs (parameters), do something with them, and can give back an output (return value). The idea dates back to the 1950s, when early programmers realised they were writing the same blocks of code over and over again.

See Functions in Action

Work through each example below. Read the code, run it, then try the suggestions underneath.

Example 1 — Defining and Calling a Function

The simplest possible function: it takes no information in and just does one thing.

Predict First! This code defines a function called greet() and then calls it. What is the difference between defining a function and calling it? Will anything happen when the def line runs, or only when greet() is called?
Hello!

Defining a function (the def block) just saves the instructions — nothing is printed yet. Only when greet() is called does the code inside run and "Hello!" appears.
Python Code
def greet():
    print("Hello!")

greet()
(click "Run Code" to see output)
Try this:
  • Call greet() three times in a row. What happens?
  • Change the message inside the function to something else, then run it again.
  • What happens if you remove the line greet() and only keep the def block? Why?

Example 2 — Parameters

Functions become much more useful when you can pass information into them. The values inside the brackets are called parameters.

Python Code
def greet(name):
    print(f"Hello, {name}!")

greet("Alice")
greet("Bob")
greet("Charlie")
(click "Run Code" to see output)
Try this:
  • Call greet() with your own name.
  • Add a second parameter called greeting so you can say greet("Alice", "Good morning").
  • What error do you get if you call greet() without any argument? Read the error message carefully.

Example 3 — Return Values

Sometimes you want a function to give a value back rather than just printing something. That is what return does.

Predict First! This function uses return instead of print(). What is the difference? When line result = add(3, 4) runs, what value gets stored in result?
7

The function calculates 3 + 4 = 7 and returns it. The value 7 is stored in the variable result. Unlike print(), return sends a value back to the caller so it can be used later.
Python Code
def add(a, b):
    return a + b

result = add(3, 4)
print(result)
(click "Run Code" to see output)
Try this:
  • Change the numbers passed to add() and check the result.
  • Create a new function called multiply that returns the product of two numbers.
  • Try using the return value directly in a print: print(add(10, 20)).

Example 4 — Default Parameters

Sometimes you want a parameter to have a default value — a fallback that is used when no argument is provided. You do this by using = in the parameter list.

Python Code
def greet(name, greeting="Hello"):
    print(f"{greeting}, {name}!")

# Calling with both arguments
greet("Alice", "Good morning")

# Calling with only one argument - uses the default
greet("Bob")

# Calling with a different greeting
greet("Charlie", "Hey there")
(click "Run Code" to see output)
Try this:
  • Change the default greeting to something else, like "Hi" or "Welcome".
  • Add a third parameter with a default value, such as punctuation="!", and use it in the f-string.
  • What happens if you put the default parameter before the non-default one? Try def greet(greeting="Hello", name): and see what Python says.

Example 5 — Multiple Return Values

A function can return more than one value at once by separating the values with commas. Python packs them into a tuple, and you can unpack them into separate variables.

Python Code
def min_max(numbers):
    return min(numbers), max(numbers)

lowest, highest = min_max([4, 7, 1, 9, 3])
print(f"Lowest: {lowest}")
print(f"Highest: {highest}")

# You can also capture both values in one variable
result = min_max([10, 20, 5, 15])
print(f"Result as a tuple: {result}")
(click "Run Code" to see output)
Try this:
  • Modify the function to also return the sum of the numbers: return min(numbers), max(numbers), sum(numbers). Remember to unpack into three variables!
  • Write a function called name_parts that takes a full name like "Alice Smith", splits it, and returns the first name and surname separately.

Example 6 — Functions Calling Other Functions

One of the most powerful ideas in programming: you can build bigger functions out of smaller ones. This is called composition or decomposition — breaking a problem into smaller, manageable parts.

Python Code
def capitalise_word(word):
    """Return the word with the first letter capitalised."""
    return word[0].upper() + word[1:].lower()

def format_name(first, last):
    """Format a full name with proper capitalisation."""
    return capitalise_word(first) + " " + capitalise_word(last)

# Test it out
name = format_name("aLiCe", "sMiTH")
print(name)

name2 = format_name("BOB", "jones")
print(name2)
(click "Run Code" to see output)
Try this:
  • Add a format_email function that calls format_name and creates an email like "Alice Smith <alice.smith@example.com>".
  • What would happen if capitalise_word was defined after format_name but before the function calls? Try it!
  • Write a format_initials function that takes a first and last name and returns just the initials, e.g. "A.S.".

How Functions Work

The anatomy of a function

Every function definition has the same structure:

Python Code
def say_hello(name):
    message = f"Hello, {name}! Welcome."
    print(message)

say_hello("Priya")
(click "Run Code" to see output)

Parameters vs arguments

These two words are often mixed up, but there is a simple difference:

TermWhere?Example
ParameterIn the function definitiondef greet(name):
ArgumentIn the function callgreet("Alice")

Think of the parameter as a label on an empty box. The argument is what you put inside that box when you use the function.

return vs print

This is one of the most important distinctions to understand:

returnprint
What it doesGives a value back to the code that called the functionDisplays text on the screen
Can you store the result?Yes — x = add(3, 4)No — x = print("hi") stores None
When to useWhen you need to use the result laterWhen you just want to show something to the user
Python Code
# Compare return vs print
def add_return(a, b):
    return a + b

def add_print(a, b):
    print(a + b)

result1 = add_return(3, 4)
result2 = add_print(3, 4)

print(f"result1 = {result1}")
print(f"result2 = {result2}")
(click "Run Code" to see output)

Procedures vs Functions — a GCSE distinction

In your GCSE exam, you need to know the difference between a function and a procedure. This catches many students out, so pay close attention:

FunctionProcedure
Does it return a value?Yes — uses returnNo — just performs an action
Python examplelen("hello") returns 5print("hello") displays text but returns None
Can you store the result?Yes — x = len("hello")No useful result to store
Python keyworddefdef (same keyword!)

In Python, both functions and procedures are created with def. Python does not have a separate keyword for procedures. However, in the exam, if a subroutine does not return a value, you should call it a procedure. If it does return a value, call it a function.

Python Code
# This is a PROCEDURE - it does something but returns nothing
def display_welcome(name):
    print(f"Welcome, {name}!")
    print("Enjoy your visit.")

# This is a FUNCTION - it returns a value
def calculate_area(length, width):
    return length * width

# Procedure - just displays output
display_welcome("Priya")

# Function - we can store and use the result
area = calculate_area(5, 3)
print(f"The area is {area} square units")
(click "Run Code" to see output)
Exam tip: Know the vocabulary

Both functions and procedures are types of subroutine (also called subprogram). A subroutine is simply a named block of code that can be called from elsewhere in the program. In the GCSE mark scheme, “subroutine” is the umbrella term, and “function” and “procedure” are the two specific types.

Why functions matter

Did you know? — Python has over 70 built-in functions You have already used several of Python’s built-in functions: print(), input(), len(), range(), type(), int(), str(), float(). But there are over 70 built-in functions in total! Others include abs() (absolute value), round(), sorted(), max(), min(), and sum(). You do not need to memorise them all — but knowing they exist will save you writing code from scratch.
Key concept: Functions must be defined before they are called Python reads your code from top to bottom. If you try to call a function above the line where it is defined, you will get a NameError. Always put your function definitions at the top of your program.
Common misconception: Defining is not calling

A very common mistake is to write a function with def but then forget to actually call it. Just defining a function does not run the code inside it — you must call it by writing the function name followed by parentheses, e.g. greet().

Python Code
# This does NOTHING visible - the function is defined but never called
def say_goodbye():
    print("Goodbye!")

# Uncomment the line below to actually run the function:
# say_goodbye()
(click "Run Code" to see output)

Scope — where variables live

Variables created inside a function only exist inside that function. This is called local scope. Variables created outside any function are in the global scope and can be seen everywhere.

Python Code
def my_function():
    secret = "I only exist inside the function"
    print(secret)

my_function()

# This next line will cause an error - try it!
# print(secret)
(click "Run Code" to see output)

Here is a more detailed example showing how local and global scope interact:

Python Code
# Global variable - accessible everywhere
school_name = "Greenfield Academy"

def print_student_info(student):
    # Local variable - only exists inside this function
    message = f"{student} attends {school_name}"
    print(message)

print_student_info("Amara")
print_student_info("James")

# We can access school_name here (it is global)
print(f"School: {school_name}")

# But we CANNOT access 'message' here (it is local)
# Uncomment the next line to see the error:
# print(message)
(click "Run Code" to see output)
Did you know? — The DRY Principle Professional programmers follow a principle called DRYDon’t Repeat Yourself. If you find yourself writing the same (or very similar) code more than once, that is a sign you should put it in a function. Functions are the main tool for achieving DRY code. The opposite of DRY is sometimes jokingly called WET — “Write Everything Twice” or “We Enjoy Typing”!

Common Mistakes

Watch out for these pitfalls. Every one of them trips up beginners (and even experienced programmers sometimes!):

MistakeWhat goes wrongHow to fix it
Defining but never callingThe function exists but the code inside it never runs.Add a function call: my_function()
Calling before definingNameError: name 'my_func' is not definedMove the function definition above the call.
Confusing return with printYou try to store the result but get None.Use return inside the function instead of print.
Wrong number of argumentsTypeError: greet() takes 1 positional argument but 2 were givenCheck how many parameters the function expects and pass exactly that many arguments.
Indentation errors in the bodyIndentationError: expected an indented blockEverything inside the function must be indented by exactly one level (4 spaces is standard).
Accessing a local variable outside the functionNameError: name 'x' is not definedEither return the value and store it, or define the variable outside the function.

Words You Need to Know

These terms come up frequently in GCSE exams. Make sure you can define each one confidently.

TermDefinition
FunctionA named block of reusable code that returns a value.
ProcedureA named block of reusable code that performs an action but does not return a value.
Subroutine / SubprogramA general term for any named block of code (covers both functions and procedures).
DefineTo create a function using the def keyword. This tells Python what the function should do.
CallTo run (execute) a function by writing its name followed by parentheses, e.g. greet().
ParameterA variable in the function definition that acts as a placeholder for data. E.g. name in def greet(name):
ArgumentThe actual value passed to a function when it is called. E.g. "Alice" in greet("Alice")
Return ValueThe value that a function sends back to the code that called it, using the return keyword.
Local VariableA variable created inside a function. It can only be used within that function.
Global VariableA variable created outside any function. It can be accessed from anywhere in the program.
ScopeThe area of a program where a variable is accessible. Local scope = inside a function; global scope = everywhere.
Built-in FunctionA function that comes with Python and is always available, like print(), len(), and input().
User-Defined FunctionA function that you write yourself using def.
DecompositionBreaking a large problem down into smaller, more manageable sub-problems — often implemented as separate functions.

Functions in the Real World

Functions are not just a school exercise — they are the foundation of how professional software is built. Here is how they are used in the real world:

Libraries and Modules

Python’s power comes from thousands of pre-built functions organised into libraries (also called modules). Instead of writing everything from scratch, you can import a library and use the functions someone else has already written and tested.

Python Code
import random
import math

# random.randint() - someone else wrote this function for us!
dice_roll = random.randint(1, 6)
print(f"You rolled a {dice_roll}")

# math.sqrt() - a pre-built function for square roots
result = math.sqrt(144)
print(f"The square root of 144 is {result}")

# math.pi - a pre-defined constant
circumference = 2 * math.pi * 5
print(f"Circumference of a circle with radius 5: {circumference:.2f}")
(click "Run Code" to see output)

APIs — Functions that talk to the internet

An API (Application Programming Interface) is essentially a set of functions that lets your program communicate with other services. When an app shows you the weather forecast, it is calling a function that fetches data from a weather service. When you post on social media, the app calls functions in the platform’s API. The world of software runs on functions talking to other functions!

Testing — Functions make code testable

Because each function does one specific job, you can test each function independently. Professional developers write “unit tests” — small checks that make sure each function works correctly. If a function is well-written, you can test it by giving it known inputs and checking the outputs, without worrying about the rest of the program.

Team work — Functions enable collaboration

In a professional software team, different developers can work on different functions at the same time. As long as everyone agrees on the function names, parameters, and return values, each team member can write and test their functions independently. The functions are then combined to create the full program. This is only possible because functions have clear inputs and outputs.

Building a Password Strength Checker

Let us work through a complete example step by step. We will write a function that checks how strong a password is — this is the kind of thing you see on websites every day when you create an account.

The Problem

Write a function called check_password_strength that takes a password string and returns a strength rating: "Weak", "Medium", or "Strong". The rules are:

Scoring: each rule the password passes earns one point. 0–1 points = “Weak”, 2–3 points = “Medium”, 4 points = “Strong”.

Step 1: Plan the logic

Before writing any code, let us plan:

  1. Take the password as a parameter
  2. Start a score counter at 0
  3. Check each rule — if the rule is met, add 1 to the score
  4. Based on the score, decide the rating
  5. Return the rating

Step 2: Write the code

For the character checks, we loop through each character and use Python’s built-in string methods: .isupper(), .islower(), and .isdigit().

Python Code
def check_password_strength(password):
    score = 0

    # Rule 1: At least 8 characters long
    if len(password) >= 8:
        score = score + 1

    # Rule 2: Contains at least one uppercase letter
    has_upper = False
    for char in password:
        if char.isupper():
            has_upper = True
    if has_upper:
        score = score + 1

    # Rule 3: Contains at least one lowercase letter
    has_lower = False
    for char in password:
        if char.islower():
            has_lower = True
    if has_lower:
        score = score + 1

    # Rule 4: Contains at least one digit
    has_digit = False
    for char in password:
        if char.isdigit():
            has_digit = True
    if has_digit:
        score = score + 1

    # Decide the rating based on the score
    if score <= 1:
        return "Weak"
    elif score <= 3:
        return "Medium"
    else:
        return "Strong"


# Test with different passwords
test_passwords = ["cat", "password", "Hello123", "MyP4ssw0rd"]

for pwd in test_passwords:
    result = check_password_strength(pwd)
    print(f"'{pwd}' -> {result}")
(click "Run Code" to see output)

Step 3: Trace through an example

Let us trace what happens when we call check_password_strength("Hello123"):

  1. score starts at 0
  2. Length check: len("Hello123") is 8, which is ≥ 8, so score becomes 1
  3. Uppercase check: "H" is uppercase, so has_upper = True, score becomes 2
  4. Lowercase check: "e", "l", "l", "o" are lowercase, so has_lower = True, score becomes 3
  5. Digit check: "1", "2", "3" are digits, so has_digit = True, score becomes 4
  6. Score is 4, so the function returns "Strong"
Try this:
  • Add a fifth rule: the password must contain at least one special character (like !, @, #). Adjust the scoring thresholds accordingly.
  • Modify the function to return the score as well as the rating, using multiple return values.

Your Turn

Work through these exercises in order. Each one builds on the skills from the last.

Exercise 1 — Personalised Greeting

Guided

Write a function called personalised_greeting that takes a person's name as a parameter and prints a friendly, personalised greeting.

For example, calling personalised_greeting("Amara") should print something like Hi Amara, welcome to Python!

Pseudocode

DEFINE function personalised_greeting that takes name
    PRINT a greeting that includes the name
END function

CALL personalised_greeting with a name

Python Code
# Exercise 1: Personalised Greeting
# Write your function below

def personalised_greeting(name):
    # Replace the line below with your greeting
    pass

# Test your function
personalised_greeting("Amara")
personalised_greeting("James")
(click "Run Code" to see output)
Hint 1

Replace pass with a print() statement. Use an f-string to include the name parameter in the message: print(f"Hi {name}, welcome to Python!")

Hint 2 — Full Solution

def personalised_greeting(name):
    print(f"Hi {name}, welcome to Python!")

Exercise 2 — Area of a Rectangle

Partially Guided

Write a function called rectangle_area that takes two parameters — length and width — and returns the area (length × width). Then call it and print the result.

Pseudocode

DEFINE function rectangle_area that takes length and width
    CALCULATE area as length multiplied by width
    RETURN area
END function

STORE the result of calling rectangle_area with two numbers
PRINT the result

Python Code
# Exercise 2: Area of a Rectangle
# Write your function below



# Test your function
area = rectangle_area(5, 3)
print(f"The area is {area}")
(click "Run Code" to see output)
Hint 1

Start with def rectangle_area(length, width): and use return (not print) to send the result back.

Hint 2

Inside the function, calculate area = length * width and then return area. You can also write it in one line: return length * width.

Hint 3 — Full Solution

def rectangle_area(length, width):
    return length * width

Exercise 3 — Mini Calculator

Open-Ended

Create a mini calculator by writing four separate functions: add, subtract, multiply, and divide. Each function should take two numbers as parameters and return the result.

Then test each function by printing its output. For the divide function, think about what should happen if someone tries to divide by zero.

Pseudocode

DEFINE function add that takes a and b
    RETURN a plus b
END function

DEFINE function subtract that takes a and b
    RETURN a minus b
END function

DEFINE function multiply that takes a and b
    RETURN a times b
END function

DEFINE function divide that takes a and b
    IF b equals 0
        RETURN an error message
    ELSE
        RETURN a divided by b
END function

CALL each function and PRINT the results

Python Code
# Exercise 3: Mini Calculator
# Write your four functions below



# Test your functions
print(f"10 + 3 = {add(10, 3)}")
print(f"10 - 3 = {subtract(10, 3)}")
print(f"10 * 3 = {multiply(10, 3)}")
print(f"10 / 3 = {divide(10, 3)}")
print(f"10 / 0 = {divide(10, 0)}")
(click "Run Code" to see output)
Hint 1

Each function follows the same pattern. For example: def add(a, b): followed by return a + b. Write all four using the correct operator (+, -, *, /).

Hint 2

For the divide function, use an if statement to check whether b == 0 before dividing. If it is zero, return the string "Error: cannot divide by zero" instead.

Hint 3 — Full Solution

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b

def multiply(a, b):
    return a * b

def divide(a, b):
    if b == 0:
        return "Error: cannot divide by zero"
    return a / b

Exercise 4 — Temperature Converter Functions

Partially Guided

Write two functions:

  • celsius_to_fahrenheit(celsius) — takes a temperature in Celsius and returns the equivalent in Fahrenheit
  • fahrenheit_to_celsius(fahrenheit) — takes a temperature in Fahrenheit and returns the equivalent in Celsius

The formulae are:

  • Fahrenheit = (Celsius × 9/5) + 32
  • Celsius = (Fahrenheit − 32) × 5/9
Pseudocode

DEFINE function celsius_to_fahrenheit that takes celsius
    CALCULATE fahrenheit as (celsius * 9/5) + 32
    RETURN fahrenheit
END function

DEFINE function fahrenheit_to_celsius that takes fahrenheit
    CALCULATE celsius as (fahrenheit - 32) * 5/9
    RETURN celsius
END function

TEST both functions with known values

Python Code
# Exercise 4: Temperature Converter Functions
# Write your two functions below



# Test your functions
print(f"0°C = {celsius_to_fahrenheit(0)}°F")       # Should be 32.0
print(f"100°C = {celsius_to_fahrenheit(100)}°F")    # Should be 212.0
print(f"32°F = {fahrenheit_to_celsius(32)}°C")      # Should be 0.0
print(f"212°F = {fahrenheit_to_celsius(212)}°C")    # Should be 100.0

# Bonus: convert and convert back - should get the original!
original = 25
converted = celsius_to_fahrenheit(original)
back_again = fahrenheit_to_celsius(converted)
print(f"{original}°C -> {converted}°F -> {back_again}°C")
(click "Run Code" to see output)
Hint 1

Each function is short — just one calculation and a return. For example: def celsius_to_fahrenheit(celsius): followed by return (celsius * 9/5) + 32.

Hint 2 — Full Solution

def celsius_to_fahrenheit(celsius):
    return (celsius * 9/5) + 32

def fahrenheit_to_celsius(fahrenheit):
    return (fahrenheit - 32) * 5/9

Exercise 5 — Shape Calculator Library

Open-Ended

Create a library of shape calculation functions. Write the following four functions, each one taking the appropriate measurements as parameters and returning the result:

  • area_of_circle(radius) — returns π × radius² (use 3.14159 for π, or import math and use math.pi)
  • area_of_triangle(base, height) — returns 0.5 × base × height
  • perimeter_of_rectangle(length, width) — returns 2 × (length + width)
  • volume_of_cube(side) — returns side³

Test each function and print the results with appropriate labels. Try to round results to 2 decimal places using the round() function.

Python Code
# Exercise 5: Shape Calculator Library
import math

# Write your four functions below



# Test your functions
print(f"Area of circle (radius 5): {round(area_of_circle(5), 2)}")
print(f"Area of triangle (base 10, height 6): {area_of_triangle(10, 6)}")
print(f"Perimeter of rectangle (4 x 7): {perimeter_of_rectangle(4, 7)}")
print(f"Volume of cube (side 3): {volume_of_cube(3)}")
(click "Run Code" to see output)
Hint 1

Each function is a single calculation. For the circle area, use math.pi * radius ** 2. For the cube volume, use side ** 3 (the ** operator means “to the power of”).

Hint 2 — Full Solution

def area_of_circle(radius):
    return math.pi * radius ** 2

def area_of_triangle(base, height):
    return 0.5 * base * height

def perimeter_of_rectangle(length, width):
    return 2 * (length + width)

def volume_of_cube(side):
    return side ** 3

Check Your Understanding

Before moving on, see if you can answer these questions. Think about each one before revealing the answer.

1. What keyword do you use to create a new function in Python?

The def keyword, followed by the function name, parentheses (with any parameters), and a colon. For example: def my_function():

2. What is the difference between a parameter and an argument?

A parameter is the variable name in the function definition (e.g. name in def greet(name):). An argument is the actual value you pass when calling the function (e.g. "Alice" in greet("Alice")).

3. What is the difference between return and print?

return sends a value back to the code that called the function, so you can store it in a variable or use it in further calculations. print simply displays text on the screen but does not give any usable value back — if you try to store the result of print(), you get None.

4. Why might you get a NameError when calling a function?

Two common reasons: (1) you tried to call the function before it was defined — Python reads top to bottom, so the definition must come first; (2) you misspelt the function name when calling it.

5. What happens if you define a function but never call it?

Nothing! The code inside the function will never run. Defining a function only tells Python what it should do — you must actually call it (e.g. greet()) for the code to execute.

6. What is the difference between a function and a procedure?

A function returns a value (using return), whereas a procedure performs an action but does not return a value. In Python, both are created using def, but the distinction matters in GCSE exams. Example of a function: def add(a, b): return a + b. Example of a procedure: def say_hello(): print("Hello").

7. What is a default parameter, and when is it useful?

A default parameter is a parameter that has a pre-set value, so the caller does not have to provide it every time. You set it with = in the definition, e.g. def greet(name, greeting="Hello"):. It is useful when a parameter usually has the same value, but you want the option to change it sometimes.

Summary

Here is everything you have learned in this chapter at a glance:

Exam-Style Questions

Practise answering these in full sentences, as you would in a GCSE exam. Click to reveal a model answer.

Q1. Explain the difference between a function and a procedure. (2 marks)

Model answer: A function is a subroutine that returns a value (1 mark) to the part of the program that called it. A procedure is a subroutine that performs an action but does not return a value (1 mark). For example, len("hello") is a function because it returns 5, while print("hello") is a procedure because it displays text but returns None.

Q2. What is meant by the ‘scope’ of a variable? Explain the difference between a local variable and a global variable. (3 marks)

Model answer: The scope of a variable refers to the part of the program where that variable can be accessed or used (1 mark). A local variable is declared inside a function and can only be used within that function (1 mark). A global variable is declared outside of any function and can be accessed from anywhere in the program (1 mark).

Q3. A student defines: def add(a, b): print(a + b) and then writes result = add(3, 4). They are surprised that result contains None. Explain why this happens and fix the code. (3 marks)

Model answer: The function uses print(), which displays the sum on the screen but does not return a value (1 mark). When a function does not explicitly use return, Python automatically returns None (1 mark). To fix the code, replace print(a + b) with return a + b so that the calculated value is sent back to the caller and stored in result (1 mark).

Fixed code: def add(a, b): return a + b

Extra Resources

Explore functions and subprograms further with these trusted resources:

Coming up next — Chapter 7: Lists Now that you can organise code into functions, it is time to learn how to organise data. In the next chapter, you will discover lists — a way to store collections of items in a single variable. You will learn to add, remove, search, and sort items in a list.