Why Does This Matter?

What if you need to store not just one name, but a whole class register? You could create 30 separate variables — student1, student2, student3… — or you could use a list.

A list lets you store multiple items in a single variable, kept in order. Think of it like a numbered container where each slot holds one piece of data. This is one of the most important ideas in programming: almost every real application works with collections of data, not just single values.

You already use lists every day without thinking about it: shopping lists, music playlists, leaderboards in games, a register of names, or even the apps on your phone’s home screen. In Python, a list works in exactly the same way — it stores items in a particular order, and you can add, remove, or change them whenever you like.

Real-World Applications

Lists are everywhere in the software you use every day:

By the end of this chapter, you will be able to:

See It in Action

Example 1: Creating and Accessing Lists

A list is created using square brackets [] with items separated by commas. Each item has a position number called an index, starting from 0.

Predict First! The list has three items: "apple", "banana", "cherry". What will fruits[0] print? What about fruits[2]? Remember: Python indexes start from 0, not 1 — this is a very common exam question!
['apple', 'banana', 'cherry']
apple
banana
cherry
Number of fruits: 3

Index 0 = "apple" (first item), index 1 = "banana", index 2 = "cherry" (last item). The list has 3 items, but the highest index is 2.
Python Code
# Creating a list of fruits
fruits = ["apple", "banana", "cherry"]

# Print the whole list
print(fruits)

# Access individual items by index
print(fruits[0])   # First item  (index 0)
print(fruits[1])   # Second item (index 1)
print(fruits[2])   # Third item  (index 2)

# How many items are in the list?
print("Number of fruits:", len(fruits))
(click "Run Code" to see output)
Try This: Change the list to contain your three favourite fruits. Then try printing fruits[-1] — what does a negative index do?

Example 2: Modifying Lists

Lists are mutable, which means you can change them after they have been created. You can add new items, remove existing ones, or change an item at a specific position.

Predict First! This code starts with ["red", "green", "blue"] and then performs four changes: append, change index 1, remove, and pop. Trace through each operation — what will the final list contain after all four changes?
Original list: ['red', 'green', 'blue']
After append: ['red', 'green', 'blue', 'yellow']
After changing index 1: ['red', 'purple', 'blue', 'yellow']
After removing blue: ['red', 'purple', 'yellow']
Popped item: yellow
Final list: ['red', 'purple']
Python Code
# Start with a list of colours
colours = ["red", "green", "blue"]
print("Original list:", colours)

# Add an item to the end
colours.append("yellow")
print("After append:", colours)

# Change an item by index
colours[1] = "purple"
print("After changing index 1:", colours)

# Remove a specific item
colours.remove("blue")
print("After removing blue:", colours)

# Remove and return the last item
last = colours.pop()
print("Popped item:", last)
print("Final list:", colours)
(click "Run Code" to see output)
Try This: Add a line that uses colours.insert(0, "orange") to put "orange" at the very start of the list. Where does it appear?

Example 3: Looping Through Lists

One of the most powerful things about lists is that you can use a for loop to go through every item automatically, one at a time.

Python Code
# A list of scores
scores = [85, 92, 78, 95, 88]

# Loop through and print each score
print("All scores:")
for score in scores:
    print("  Score:", score)

# Calculate the total using a loop
total = 0
for score in scores:
    total = total + score

average = total / len(scores)
print("Total:", total)
print("Average:", average)
(click "Run Code" to see output)
Try This: Change the scores to your own test marks from this term. Add more items to the list and see how the average updates automatically.

Example 4: List Slicing

Slicing lets you extract a portion of a list without changing the original. The syntax is list[start:stop], where start is included and stop is excluded. You can also add a step value: list[start:stop:step].

Python Code
# A list of days
days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

# Slice from index 1 up to (not including) index 3
print(days[1:3])       # ["Tue", "Wed"]

# Slice from the start up to index 2
print(days[:2])        # ["Mon", "Tue"]

# Slice from index 4 to the end
print(days[4:])        # ["Fri", "Sat", "Sun"]

# Every second item (step of 2)
print(days[::2])       # ["Mon", "Wed", "Fri", "Sun"]

# Reverse the entire list using a step of -1
print(days[::-1])      # ["Sun", "Sat", "Fri", ...]

# Get the weekdays only (first 5)
weekdays = days[:5]
print("Weekdays:", weekdays)

# Get the weekend only (last 2)
weekend = days[5:]
print("Weekend:", weekend)
(click "Run Code" to see output)
Try This: What does days[1:6:2] produce? Predict the answer first, then run the code to check. Can you write a slice that returns only ["Wed", "Thu", "Fri"]?

Example 5: Sorting Lists

Python makes it easy to sort lists into order. The .sort() method changes the list in place (it modifies the original), while the sorted() function returns a new sorted list and leaves the original unchanged.

Python Code
# Sorting numbers
scores = [45, 82, 67, 91, 73]
print("Original:", scores)

# Sort ascending (modifies the list)
scores.sort()
print("Ascending:", scores)

# Sort descending
scores.sort(reverse=True)
print("Descending:", scores)

# Using sorted() to create a NEW sorted list
names = ["Charlie", "Alice", "Eve", "Bob", "Diana"]
print("\nOriginal names:", names)

alphabetical = sorted(names)
print("Sorted copy:", alphabetical)
print("Original unchanged:", names)

# Sort the original in place
names.sort()
print("Now sorted in place:", names)
(click "Run Code" to see output)
Try This: What happens if you try to sort a list that contains both strings and numbers, like ["apple", 3, "banana"]? Try it and see what error you get. Why do you think this happens?

Example 6: 2D Lists (Lists of Lists)

A 2D list is a list where each item is itself a list. This is perfect for representing grids, tables, or matrices. Think of a spreadsheet: each row is a list, and the whole spreadsheet is a list of rows.

Python Code
# A 3x3 grid stored as a 2D list
# Each inner list is one row
grid = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
]

# Access a whole row (the second row, index 1)
print("Row 1:", grid[1])         # [4, 5, 6]

# Access a single cell: grid[row][column]
print("Row 0, Col 1:", grid[0][1])  # 2
print("Row 2, Col 2:", grid[2][2])  # 9

# A more practical example: student marks
# Each row = [Name, Maths, English, Science]
students = [
    ["Alice", 85, 92, 78],
    ["Bob", 91, 67, 83],
    ["Charlie", 76, 88, 95]
]

# Print each student's details
print("\nStudent Report:")
for student in students:
    name = student[0]
    avg = (student[1] + student[2] + student[3]) / 3
    print(f"  {name}: average = {avg:.1f}")
(click "Run Code" to see output)
Try This: Add a fourth student to the students list with your own name and three marks. Run the code again to see them appear in the report. Can you also print the student with the highest average?

How Does It Work?

List Syntax

A list is created with square brackets, and each item is separated by a comma:

my_list = ["item1", "item2", "item3"]

Lists can hold strings, integers, floats, booleans — even a mixture of types — although in practice you will usually store items of the same type in a single list.

# A list with mixed types (valid, but uncommon)
mixed = ["Alice", 16, True, 9.5]
Did You Know? Python lists can hold any mix of data types in the same list. This is different from arrays in languages like C or Java, where every element must be the same type. In Python, you could store a string, an integer, a boolean, and even another list all inside one list. This flexibility is one of the reasons Python is so popular for beginners and professionals alike.

Indexing: It Starts at 0

Every item in a list has a position number called its index. The crucial thing to remember is that indexing starts at 0, not 1.

Item "apple" "banana" "cherry"
Index 0 1 2

You can also use negative indexing to count backwards from the end of the list. -1 is the last item, -2 is the second-to-last, and so on.

fruits = ["apple", "banana", "cherry"]
print(fruits[-1])   # cherry  (last item)
print(fruits[-2])   # banana  (second-to-last)
Key Concept: Lists are mutable — you can change their contents after creation. This is different from strings, which cannot be changed once created. You can add, remove, replace, and reorder list items at any time.

Common List Methods

Python gives you many built-in methods to work with lists. Here are the ones you will use most often:

Method / Function What It Does Example
append(item) Adds an item to the end of the list fruits.append("mango")
insert(index, item) Inserts an item at a specific position fruits.insert(1, "kiwi")
remove(item) Removes the first occurrence of the item fruits.remove("banana")
pop() Removes and returns the last item (or item at a given index) last = fruits.pop()
sort() Sorts the list in ascending order (in place) fruits.sort()
sorted(list) Returns a new sorted list (original unchanged) new = sorted(fruits)
reverse() Reverses the list in place fruits.reverse()
index(item) Returns the index of the first occurrence pos = fruits.index("kiwi")
count(item) Counts how many times an item appears n = fruits.count("apple")
len(list) Returns the number of items in the list print(len(fruits))
in Checks if an item exists in the list if "kiwi" in fruits:

Looping Through a List

Using a for loop with a list is one of the most common patterns in Python. The loop variable takes the value of each item in turn:

for item in my_list:
    print(item)

If you also need the index number alongside the item, you can use enumerate():

for index, item in enumerate(my_list):
    print(index, item)

This links directly to what you learnt in Chapter 5: Loops. The for loop is the natural partner of a list.

Slicing in Detail

List slicing uses the syntax list[start:stop:step]. All three values are optional:

Slice Meaning Example (nums = [10, 20, 30, 40, 50]) Result
nums[1:3] From index 1 up to (not including) 3 Items at index 1 and 2 [20, 30]
nums[:2] From the start up to index 2 First two items [10, 20]
nums[3:] From index 3 to the end Last two items [40, 50]
nums[::2] Every second item Items at index 0, 2, 4 [10, 30, 50]
nums[::-1] All items in reverse order Reversed list [50, 40, 30, 20, 10]

Slicing always creates a new list — it never changes the original.

Arrays vs Lists — What the GCSE Exam Expects

In your GCSE Computer Science exam, the term “array” is used rather than “list”. It is important to understand that in Python, a list is the same concept as an array. Python does not have a separate built-in “array” data type in the way that languages like C or Java do — instead, Python uses lists to do the same job.

Did You Know? The GCSE exam board (Edexcel, AQA, OCR) uses the term “array”, but Python uses the term “list”. They are the same concept. If an exam question says “declare an array called names”, you should write names = [] in Python. Whenever you see “array” in an exam, just think “list”.

1D Arrays (One-Dimensional)

A 1D array is a single row of items — what we have been calling a list so far:

# A 1D array of names
names = ["Alice", "Bob", "Charlie", "Diana"]

This stores one sequence of items in a straight line. You access items with a single index: names[2] returns "Charlie".

2D Arrays (Two-Dimensional)

A 2D array stores data in rows and columns, like a table or spreadsheet. In Python, you create this as a list of lists — each inner list is one row:

# A 2D array: 3 rows, 4 columns
# Each row = [Name, Maths, English, Science]
marks = [
    ["Alice", 85, 92, 78],
    ["Bob", 91, 67, 83],
    ["Charlie", 76, 88, 95]
]

You access items using double indexing: marks[row][column]. For example:

When the exam asks you to “use a 2D array”, this is how you do it in Python.

Did You Know? Python’s built-in sort algorithm is called Timsort, and it was invented by Tim Peters in 2002. It was specifically designed for Python and is named after him. Timsort is so efficient that it was later adopted by Java, Android, and many other platforms. When you call .sort() or sorted(), Timsort is running behind the scenes.

Key Vocabulary

These are the key terms you need to know for this topic. Make sure you can define each one:

Term Definition
List An ordered, mutable collection of items stored in a single variable. Created with square brackets [].
Array The term used in GCSE exams for a list. In Python, arrays and lists are the same thing.
Index The position number of an item in a list, starting from 0.
Element / Item A single value stored inside a list. For example, in ["a", "b"], "a" is an element.
Mutable Can be changed after creation. Lists are mutable; strings are not.
Append Add an item to the end of a list using .append().
Insert Add an item at a specific index position using .insert(index, item).
Remove Delete an item by its value using .remove(value).
Pop Remove and return an item by its index using .pop(index). Defaults to the last item.
Sort Rearrange items into order. .sort() modifies the list; sorted() creates a new one.
Slice Extract a portion of a list using list[start:stop:step] syntax.
len() A built-in function that returns the number of items in a list.
Iterate / Traverse Go through every item in a list one at a time, usually with a for loop.
2D Array An array with rows and columns — in Python, a list of lists.
Nested List A list contained inside another list. Used to create 2D structures.

Common Mistakes

Watch out — Off-by-one error: The most common mistake with lists is forgetting that the first index is 0, not 1. If your list has 5 items, the valid indices are 0, 1, 2, 3, and 4. Trying to access list[len(list)] will cause an IndexError because the last valid index is len(list) - 1. For example, if scores = [10, 20, 30], then scores[3] crashes, but scores[2] gives you 30.
Watch out — Modifying a list while looping: If you remove items from a list while looping through it with a for loop, Python can skip items or crash. This is because the indices shift when an item is removed. Instead, create a new list with only the items you want to keep, or loop through a copy of the list.
Watch out — remove() vs pop(): remove() deletes by value, not by position. If you write my_list.remove(3), Python removes the item whose value is 3, not the item at index 3. To remove by position, use pop(index). Getting these mixed up is a very common mistake.
Watch out — .sort() returns None: A common mistake is writing sorted_list = my_list.sort(). The .sort() method modifies the list in place and returns None, so sorted_list would be None, not a sorted list. If you want a new sorted list, use sorted_list = sorted(my_list) instead.

Worked Example: Building a Class Register

Let’s work through a complete example step by step. We will build a class register program that demonstrates many of the list operations you have learnt.

Scenario: You are a form tutor. You need to create a register of student names, handle a late arrival, remove a student who has left the school, sort the register alphabetically, check if a specific student is in your class, and count the total number of students.

Python Code — Worked Example
# WORKED EXAMPLE: Class Register
# =================================

# Step 1: Create the initial register
register = ["Emily", "James", "Priya", "Oliver", "Fatima"]
print("Initial register:", register)
print("Number of students:", len(register))

# Step 2: A late student arrives - add them to the end
register.append("Liam")
print("\nAfter Liam arrives late:", register)

# Step 3: Oliver has left the school - remove him
register.remove("Oliver")
print("After Oliver leaves:", register)

# Step 4: Sort the register alphabetically
register.sort()
print("\nSorted alphabetically:", register)

# Step 5: Check if a specific student is in the class
search_name = "Priya"
if search_name in register:
    position = register.index(search_name)
    print(f"\n{search_name} is in the register at position {position}")
else:
    print(f"\n{search_name} is NOT in the register")

# Step 6: Count total students
print(f"\nTotal students in class: {len(register)}")

# Bonus: Print a numbered register
print("\n--- Final Register ---")
for i in range(len(register)):
    print(f"  {i + 1}. {register[i]}")
(click "Run Code" to see output)

Key points from this example:

Your Turn

Exercise 1: Favourite Foods
Guided

Create a list containing 5 of your favourite foods, then use a for loop to print each one on its own line. After the loop, print how many foods are in your list.

Pseudocode:
STEP 1: Create a list called foods with 5 items
STEP 2: Use a for loop to go through each food in the list
STEP 3: Inside the loop, print the food
STEP 4: After the loop, print the length of the list
Your Code
# Exercise 1 - Favourite Foods
# Step 1: Create your list of 5 favourite foods
foods = ["____", "____", "____", "____", "____"]

# Step 2 & 3: Loop through and print each food
for food in ____:
    print(____)

# Step 4: Print how many foods are in the list
print("I have", ____(____),"favourite foods!")
(click "Run Code" to see output)
Need a hint?
Replace each ____ with the correct values. The loop variable food holds each item in turn, so you can print it directly. Use len(foods) to get the total number of items.
Exercise 2: To-Do List Manager
Partially Guided

Create a simple to-do list program. Start with a few tasks already in the list, then add a new task using append(), remove a completed task using remove(), and print the final list.

Pseudocode:
STEP 1: Create a list called tasks with 3 starting items
STEP 2: Print the original list of tasks
STEP 3: Append a new task to the list
STEP 4: Remove one completed task from the list
STEP 5: Print the updated list
STEP 6: Print how many tasks remain
Your Code
# Exercise 2 - To-Do List Manager
# Step 1: Create your starting task list
tasks = ["Do homework", "Tidy room", "Walk the dog"]
print("My to-do list:", tasks)

# Step 3: Add a new task

# Step 4: Remove a completed task

# Step 5: Print the updated list
print("Updated to-do list:", tasks)

# Step 6: Print how many tasks remain
(click "Run Code" to see output)
Need a hint?
To add a task, use tasks.append("Your new task"). To remove a task, use tasks.remove("Tidy room") (or whichever task you have completed). Remember the string must match exactly, including capital letters.
Exercise 3: Student Score Analyser
Open-Ended

Create a program that stores a list of student scores, then finds the highest score, the lowest score, and calculates the average. Print all three results with clear labels.

Pseudocode:
STEP 1: Create a list of at least 6 student scores
STEP 2: Find the highest score (you could use max() or a loop)
STEP 3: Find the lowest score (you could use min() or a loop)
STEP 4: Calculate the total of all scores
STEP 5: Calculate the average (total divided by number of scores)
STEP 6: Print the highest, lowest, and average with labels
Your Code
# Exercise 3 - Student Score Analyser
# Build a program that analyses a list of scores

# Your code here
(click "Run Code" to see output)
Need a hint?
Python has built-in functions max(), min(), and sum() that work on lists of numbers. For example, max(scores) returns the highest value. To calculate the average, divide sum(scores) by len(scores). For an extra challenge, try finding the highest score using a loop and an if statement instead of max().
Exercise 4: Top 5 Leaderboard
Partially Guided

You are building a game leaderboard. Store player scores in a list, sort them in descending order (highest first), display only the top 5, then add a new score and re-sort the leaderboard.

Pseudocode:
STEP 1: Create a list called scores with at least 8 integer scores
STEP 2: Sort the scores in descending order (highest first)
STEP 3: Use slicing to get only the top 5 scores
STEP 4: Print the top 5 leaderboard with numbered positions
STEP 5: A new player scores 88 — append it to the full list
STEP 6: Re-sort in descending order and display the new top 5
Your Code
# Exercise 4 - Top 5 Leaderboard

# Step 1: Create a list of scores
scores = [72, 95, 43, 88, 61, 100, 55, 79]

# Step 2: Sort descending (highest first)

# Step 3: Slice the top 5

# Step 4: Print the top 5 with positions
print("=== LEADERBOARD ===")

# Step 5: Add a new score of 88

# Step 6: Re-sort and display new top 5
print("\n=== UPDATED LEADERBOARD ===")
(click "Run Code" to see output)
Need a hint?
To sort descending, use scores.sort(reverse=True). To get the top 5, use a slice: top_five = scores[:5]. To print numbered positions, loop with for i in range(len(top_five)) and print f"{i + 1}. {top_five[i]}". After appending 88, just sort and slice again.
Exercise 5: Lottery Number Generator
Open-Ended

Write a program that generates 6 random lottery numbers between 1 and 59 (no duplicates), sorts them in ascending order, and displays them in a formatted way. You will need the random module.

Pseudocode:
STEP 1: Import the random module
STEP 2: Create an empty list called numbers
STEP 3: Use a while loop to keep generating random numbers until you have 6 unique ones
STEP 4: Inside the loop, generate a random number between 1 and 59 using random.randint(1, 59)
STEP 5: Only append the number if it is not already in the list
STEP 6: Sort the list in ascending order
STEP 7: Print the lottery numbers in a clear format
Your Code
# Exercise 5 - Lottery Number Generator
# Generate 6 unique random numbers between 1 and 59
import random

# Your code here
(click "Run Code" to see output)
Need a hint?
Start with numbers = []. Use while len(numbers) < 6: to keep looping. Generate a number with num = random.randint(1, 59). Check if num not in numbers: before appending. After the loop, call numbers.sort(). For a shortcut, you could also try random.sample(range(1, 60), 6) which picks 6 unique values in one line.

Think About It

Chapter Summary

In this chapter, you have learnt:

Exam-Style Questions

Practise answering these in full sentences, as you would in a GCSE exam:

Question 1 (2 marks)

What is meant by the term “array” (list) in programming?

Give a definition and state one feature of an array.

Reveal model answer

An array (or list) is a data structure that stores multiple values in a single variable (1 mark). The values are stored in an ordered sequence and each item can be accessed by its index position (1 mark).

Question 2 (4 marks)

Explain the difference between a 1D array and a 2D array. Give an example of when each would be used.

Reveal model answer

A 1D array stores data in a single row/sequence (1 mark). For example, storing a list of student names: ["Alice", "Bob", "Charlie"] (1 mark).

A 2D array stores data in rows and columns, like a table (1 mark). For example, storing student names alongside their marks in different subjects, where each row contains a name and multiple scores (1 mark).

Question 3 (3 marks)

A list contains: scores = [45, 82, 67, 91, 73]

Write Python code to:

(a) Add the value 88 to the end of the list. (1 mark)

(b) Remove the value 45 from the list. (1 mark)

(c) Print the highest score. (1 mark)

Reveal model answer

(a) scores.append(88)

(b) scores.remove(45)

(c) print(max(scores))

Alternative for (c): sort the list and print the last element, or use a loop to find the maximum.

Extra Resources

Deepen your understanding with these trusted resources:

What’s Next?

Lists are brilliant for storing collections of items, but what if you want to store not just values, but pairs of related information? For example, a student’s name and their score together. In Chapter 8: Dictionaries, you will learn how to link keys to values — unlocking a whole new way of organising data.