Python lists
A list is Python's built-in way to store many values in order, and it appears in every UK GCSE Computer Science specification (called an 'array' in the pseudocode). This unit covers creating lists, indexing (l[0]) and slicing (l[1:4]), the common list methods (.append(), .remove(), .pop(), .insert()), and iterating over a list with for. Every example runs in the browser so learners can watch the list change as items are added and removed. Perfect for classroom teaching, GCSE and A Level revision, and independent or home-schooled learners.
What you'll learn
- Create a list with square brackets: scores = [10, 20, 30]
- Access items by index: scores[0]
- Modify items by assignment: scores[0] = 99
- Grow a list with .append(); remove with .remove() or .pop()
- Loop over a list with for item in list
- Use len(list) to count items
UK GCSE topic coverage
- Lists (arrays)
- List indexing
- List length
- List mutation
- for over items
- for + index
- List methods (`.append()`)
- Functions that take/return lists
- Sequences and mutability
- Applied lists
Worked example
Build a list of scores and print the highest
scores = []
for _ in range(3):
scores.append(int(input("Score? ")))
print("Highest:", max(scores))Try a full unit free with a RunPy account
Sign up free and get the whole of Unit 1 (Input, Output and Variables) with checked tasks and instant feedback, plus a selection of the exam-style questions so you can practice on real GCSE-style content before upgrading.
Lessons in this unit
Full interactive lessons with checked tasks are available to signed-in RunPy users. Unit 1 and a selection of exam-style questions are free with a RunPy account.
- What is a list?
- Accessing list items
- Negative indexing and boundaries
- List length with len()
- Updating list items
- Iterating over a list with for
- Iterating with index using range() and len()
- Building lists with .append()
- Using functions with lists
- Lists and strings: comparing the two
- Composite list challenge
Frequently asked questions
- What's the difference between a Python list and an array?
- In GCSE pseudocode the term is 'array'. In Python you use a list, which is essentially the same thing for GCSE purposes. Python does have an actual array type but it's not needed at this level.
- Are Python lists zero-indexed?
- Yes. The first item is at index 0. Negative indices count from the end: list[-1] is the last item.
- How do I remove an item from a list?
- .remove(value) removes the first item equal to value. .pop() removes and returns the last item. .pop(i) removes and returns the item at index i.