An array (or list in Python) is a single named variable that can hold multiple values at once, stored in a specific order and accessed using an index number. Instead of creating separate variables for every item, one list lets you manage a whole collection of related data together.
Why do we need arrays and lists?
Suppose you want to store the scores of 30 students in a class. Without a list, you would need 30 separate variables — score1, score2, … score30. Processing all of them would require 30 separate lines of code. With a list, all 30 scores sit in one structure, and a loop can process all of them in just a few lines. Arrays and lists are covered in GCSE Computer Science specifications (AQA, OCR, Edexcel) and introduced at KS3 in most school schemes of work.
How do you create and access a list in Python?
scores = [72, 85, 61, 94, 78]
Each item has an index — a position number starting at 0 (not 1):
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Value | 72 | 85 | 61 | 94 | 78 |
Accessing elements:
print(scores[0]) # Outputs: 72 (first item)
print(scores[2]) # Outputs: 61 (third item)
print(scores[-1]) # Outputs: 78 (last item — negative indexing)
Changing an element:
scores[1] = 90 # Changes 85 to 90
How do you add and remove items from a list?
scores.append(88) # Adds 88 to the end
scores.insert(0, 55) # Inserts 55 at index 0 (shifts all others right)
scores.remove(61) # Removes the first occurrence of the value 61
popped = scores.pop() # Removes and returns the last item
After append(88), the list grows by one. pop() both removes and returns the item — useful if you want to process the item you are removing.
Looping through a list
The most common way to process every item in a list is a for loop:
scores = [72, 85, 61, 94, 78]
total = 0
for score in scores:
total = total + score
average = total / len(scores)
print("Average:", average)
Worked trace:
| Loop iteration | score |
total |
|---|---|---|
| 1 | 72 | 72 |
| 2 | 85 | 157 |
| 3 | 61 | 218 |
| 4 | 94 | 312 |
| 5 | 78 | 390 |
average = 390 / 5 = 78.0
len(scores) returns the number of items in the list (5 in this case). Using len() instead of the number 5 makes the code work correctly even if the list changes size.
Searching a list: linear search
To find whether a particular value is in a list, a linear search checks each item one by one:
def linear_search(data, target):
for i in range(len(data)):
if data[i] == target:
return i # Return the index where target was found
return -1 # Return -1 if not found
scores = [72, 85, 61, 94, 78]
result = linear_search(scores, 94)
print(result) # Outputs: 3 (index of 94)
Linear search checks every element in the worst case — it is simple but slow for large lists. Binary search (covered at GCSE) is much faster but requires a sorted list first.
What is the difference between an array and a list in Python?
In many programming languages, an array has a fixed size declared at creation and can only hold one data type. In Python, the equivalent built-in structure is a list, which is more flexible:
| Feature | Traditional array (e.g. in Java) | Python list |
|---|---|---|
| Size | Fixed at creation | Dynamic — grows or shrinks |
| Data types | One type only (e.g. all integers) | Mixed types allowed |
| Syntax example | int[] scores = new int[5]; |
scores = [72, 85, 61, 94, 78] |
GCSE Computer Science exam questions often use the word "array" even when discussing Python lists. For exam purposes, treat them as equivalent.
A practical example: storing and grading test scores
scores = [72, 85, 61, 94, 78]
names = ["Amara", "Ben", "Cleo", "Dan", "Effy"]
for i in range(len(scores)):
if scores[i] >= 80:
grade = "Distinction"
elif scores[i] >= 60:
grade = "Merit"
else:
grade = "Pass"
print(names[i] + ": " + grade)
Output:
Amara: Merit
Ben: Distinction
Cleo: Merit
Dan: Distinction
Effy: Merit
Using range(len(scores)) with a counter variable i lets you access the same index position in two different lists simultaneously (names[i] and scores[i]).
Frequently asked questions
Why does list indexing start at 0, not 1?
Index numbering from 0 is a convention inherited from low-level languages like C, where the index represents a memory offset from the start of the array. If each element takes 4 bytes, the first element is at offset 0 (0 × 4 = 0 bytes from the start), the second at offset 1 (1 × 4 = 4 bytes), and so on. Starting at 0 makes the memory arithmetic clean. Most modern languages (Python, Java, JavaScript, C) follow this convention.
What happens if you use an index that is too large?
Python raises an IndexError — a runtime error indicating you tried to access a position that does not exist. For example, if a list has 5 items (indices 0–4) and you try scores[5], Python raises IndexError: list index out of range. This is one of the most common beginner programming errors. Always remember that the valid indices for a list of n items are 0 to n−1.
Can a list contain another list?
Yes — a list can contain any data type, including other lists. This creates a 2D list (or 2D array), useful for representing grids, tables, or matrices: grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]. Accessing an element requires two indices: grid[1][2] retrieves the item at row 1, column 2 — the value 6. 2D lists appear in GCSE specifications for AQA and OCR.
How do you find the largest value in a list?
Python has a built-in max() function: largest = max(scores). Alternatively, you can implement it manually with a loop — and understanding the manual approach is important for GCSE, as examiners often ask you to trace or write the find-maximum algorithm. Start with largest = scores[0], then loop through the remaining elements, updating largest whenever you find a bigger value.
For Socratic KS3 and GCSE computing tutoring — lists, algorithms, and Python programming — visit aitutors.me.