Edexcel 1CP2 · GCSE Computer Science · ~11 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz
Tuples
A tuple is an ordered, immutable (unchangeable) collection of items. Once created, items cannot be added, removed, or changed. Defined with parentheses ().
# Creating tuplescoordinates = (51.5, -0.12) # latitude, longitudergb = (255, 128, 0) # colour valuesdays = ("Mon", "Tue", "Wed")# Accessing (same as lists)print(coordinates[0]) # 51.5print(rgb[-1]) # 0# Cannot modify a tuple# rgb[0] = 200 → TypeError: tuple does not support item assignment
When to use tuples vs lists: Use a tuple when the data should NOT change (fixed set of values like days of the week, coordinates, or configuration values). Use a list when the data needs to be modified.
Feature
List
Tuple
Syntax
[1, 2, 3]
(1, 2, 3)
Mutable?
Yes — can change
No — fixed
Ordered?
Yes
Yes
Indexing
lst[0]
tpl[0]
Use case
Data that changes
Fixed/constant data
Dictionaries
A dictionary stores data as key-value pairs. Each key is unique. Access values by key, not by index. Defined with curly braces {}.
person = {"name": "Bob", "age": 20}# Adding/updatingperson["email"] = "bob@email.com"# add new keyperson["age"] = 21# update existing# Removingdel person["email"] # delete a key# Checking membershipif"name"in person:print("Has name!") # True# .get() — safe access (returns None if key missing)print(person.get("phone", "N/A")) # "N/A" — no error
Iterating Over Dictionaries
scores = {"Maths": 85, "English": 72, "Science": 91}for subject in scores: # iterates over KEYSprint(subject, scores[subject])for key, value in scores.items():print(key, "→", value)print(list(scores.keys())) # ['Maths', 'English', 'Science']print(list(scores.values())) # [85, 72, 91]
Exam tip: Dictionaries are excellent for storing structured records (like a student profile with name, age, grade). Edexcel may ask you to access, update or iterate over dictionaries. Remember: keys are unique strings (or numbers), values can be any type.
⚠️ Common Mistakes
Trying to modify a tuple — will cause a TypeError (use a list if data needs to change)
Using an index to access a dictionary — dict[0] means key 0, NOT the first item
Duplicate keys in a dictionary — the second definition overwrites the first silently
KeyError when accessing a missing key — use .get() for safe access
Confusing tuples (parentheses) with lists (square brackets) in syntax
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
✍️
Worksheet — 6.3b Tuples & Dictionaries
8 Edexcel-style questions · instantly marked
Q1What is the key difference between a tuple and a list in Python?[2]
✅ Mark scheme
A tuple is immutable (cannot be changed after creation) [1]; a list is mutable (items can be added, removed, or changed) [1]. Both are ordered and support indexing.
Q2Given: student = {"name": "Alice", "age": 16, "grade": "A"}. Write the code to: (a) print the student's name (b) update the age to 17 (c) add a new key "school" with value "Oak Academy".[3]
✅ Mark scheme
(a) print(student["name"]) [1]; (b) student["age"] = 17 [1]; (c) student["school"] = "Oak Academy" [1]. Note: accessing a dictionary value uses the KEY in square brackets, not an index number.
Q3Write Python code to create a dictionary called 'capitals' with at least 3 country-capital pairs, then print the capital of one country using its key.[3]
✅ Mark scheme
capitals = {"UK": "London", "France": "Paris", "Germany": "Berlin"} (or any valid countries) [2 — 1 for structure, 1 for at least 3 pairs]; print(capitals["UK"]) or similar [1]. Keys must be unique.
Q4Give ONE real-world example where a tuple would be more appropriate than a list. Explain why.[2]
✅ Mark scheme
Example: storing GPS coordinates (latitude, longitude) [1]; because coordinates should not change once set — immutability prevents accidental modification, and the data is inherently fixed (accept: RGB colour values, days of the week, date of birth — any appropriate fixed data) [1].
Q5Write a for loop to print every key and value from the dictionary: prices = {"apple": 0.50, "banana": 0.30, "cherry": 1.20}.[3]
✅ Mark scheme
for fruit, price in prices.items(): [2 — 1 for .items(), 1 for two variables]; print(fruit, price) [1]. Accept: for fruit in prices: print(fruit, prices[fruit]) — alternative correct approach [3 marks].
Q6What is the output of: t = (10, 20, 30, 40); print(t[2]); print(len(t))?[2]
✅ Mark scheme
30 [1] — t[2] is index 2 = third item = 30 (indices: 0→10, 1→20, 2→30, 3→40); 4 [1] — len() of a 4-item tuple = 4. Tuples support indexing and len() just like lists.
Q7Explain what happens when you try to run: my_tuple = (1, 2, 3); my_tuple[0] = 10. Why does this happen?[2]
✅ Mark scheme
A TypeError is raised [1]; because tuples are immutable — once created, their elements cannot be changed, added to, or removed [1]. If you need to modify data, use a list instead.
Q8A student record system stores: name, student ID, and subjects (a list). Write Python code to create a dictionary for one student and show how to add a new subject to their subjects list.[4]
✅ Mark scheme
student = {"name": "Alice", "id": "S001", "subjects": ["Maths", "Science"]} [2 — 1 for structure, 1 for subjects as a list]; student["subjects"].append("English") [2 — 1 for accessing the key correctly, 1 for .append()]. Demonstrates a list nested inside a dictionary.
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
Term
Definition
🎯
Mini Test — Tuples & Dictionaries
Timed exam-style test — 10 minutes.
⏱10:00
Section A — Multiple Choice [5 marks]
Q1Which Python structure is IMMUTABLE?[1]
Q2How do you access the value for key "name" in a dictionary called 'person'?[1]
Q3What does t = (1, 2, 3) create?[1]
Q4Which method returns all key-value pairs from a dictionary for iteration?[1]
Q5d = {"a": 1, "b": 2, "a": 3}. What is d["a"]?[1]
Section B — Short Answer
Q6Write Python code to create a dictionary for a book with keys: title, author, year. Then use a for loop to print every key and value.[3]
Mark schemebook = {"title": "...", "author": "...", "year": ...} [2 — 1 for structure, 1 for 3 keys]; for key, value in book.items(): [1]; print(key, value) [1].
Q7Why would you use a tuple instead of a list to store the (x, y) coordinates of a point?[2]
Mark schemeCoordinates are fixed values that should not change [1]; a tuple is immutable so it prevents accidental modification, making the code safer and clearer in intent [1].