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:
- Spotify — A playlist is a list of songs. When you add a track, reorder your queue, or shuffle, the app is manipulating a list behind the scenes.
- Instagram — Your feed is a list of posts, loaded in order. As you scroll, the app fetches more items and appends them to the list.
- Games — Inventory systems store items in lists. When you pick up a sword or use a health potion, the game adds to or removes from your inventory list.
- E-commerce (Amazon, ASOS) — Your shopping basket is a list of products. Adding an item calls
append(); removing one callsremove()— exactly the same operations you will learn in this chapter. - Databases — When a website queries its database (e.g. “find all orders from today”), the results come back as a list of records that the program then loops through and displays.
By the end of this chapter, you will be able to:
- Create lists that hold multiple items
- Access individual items using their index position
- Add and remove items from a list
- Loop through a list to process every item
- Use
len()to find out how many items a list contains - Slice lists to extract portions of data
- Sort lists in ascending and descending order
- Create and access 2D lists (lists of lists)
- Understand the difference between the terms “list” and “array” for your GCSE exam
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.
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
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.
# 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))
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.
["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?
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']
# 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)
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.
# 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)
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].
# 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)
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.
# 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)
["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.
# 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}")
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]
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)
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.
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:
marks[0][0]→"Alice"(row 0, column 0)marks[1][2]→67(row 1, column 2 — Bob’s English mark)marks[2][3]→95(row 2, column 3 — Charlie’s Science mark)
When the exam asks you to “use a 2D array”, this is how you do it in Python.
.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
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.
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.
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.
.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.
# 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]}")
Key points from this example:
append()adds the late student to the end of the list.remove()finds and deletes a student by their name (value).sort()puts the names in alphabetical (A-Z) order.- The
inkeyword checks whether a name exists in the list. index()tells us the position of a name in the sorted list.len()gives the total count at any point.- We use
range(len(register))to loop with a counter, so we can print numbered lines.
Your Turn
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.
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
# 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!")
____ 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.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.
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
# 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
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.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.
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
# Exercise 3 - Student Score Analyser
# Build a program that analyses a list of scores
# Your code here
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().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.
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
# 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 ===")
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.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.
random moduleSTEP 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
# Exercise 5 - Lottery Number Generator
# Generate 6 unique random numbers between 1 and 59
import random
# Your code here
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
- Why do you think Python starts counting list indices at 0 instead of 1?
- If you had a list of 100 student names, how would a loop be better than accessing each one individually?
- What is the difference between
remove()andpop()? When would you use each one? - Can you think of three examples from real life where data is naturally stored as a list?
- What is the difference between
.sort()andsorted()? When might you prefer one over the other? - When would you use a 2D list instead of a 1D list? Think of an example from a real application.
Chapter Summary
In this chapter, you have learnt:
- A list stores multiple items in a single variable, in order, using square brackets.
- Indexing starts at 0. The last item is at index
len(list) - 1, or you can use-1. - Lists are mutable — you can add (
append,insert), remove (remove,pop), and change items after creation. - A
forloop is the natural way to iterate (traverse) through every item in a list. - Slicing with
list[start:stop:step]lets you extract portions of a list without changing the original. .sort()sorts a list in place (and returnsNone);sorted()returns a new sorted list.- A 2D list (list of lists) represents rows and columns, accessed with double indexing:
grid[row][col]. - In GCSE exams, the term “array” means the same thing as a Python list. A 1D array is a single list; a 2D array is a list of lists.
Exam-Style Questions
Practise answering these in full sentences, as you would in a GCSE exam:
What is meant by the term “array” (list) in programming?
Give a definition and state one feature of an array.
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).
Explain the difference between a 1D array and a 2D array. Give an example of when each would be used.
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).
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)
(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:
- BBC Bitesize — Edexcel GCSE Computer Science — Revision notes covering arrays, data types, and programming concepts
- W3Schools — Python Lists — Interactive reference with try-it-yourself examples for every list method
- Array Learning Game — Interactive 1D and 2D array challenges with drag-and-drop
- Array Search Builder — Build array searching programs step by step
- GCSE Topic 6: Data Types — Arrays, lists, and 2D arrays with interactive code editors
- GCSE Topic 1: Searching & Sorting — Linear search, binary search, bubble sort, and merge sort in Python
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.