← Python

Tuples – Basics

A tuple is an immutable ordered sequence of values defined with parentheses or commas

What it does: Python evaluates the right side as a tuple before assigning. Returning x, y is shorthand for returning the tuple (x, y). Returning multiple values with commas automatically packs them into a tuple. A point (x, y) shouldn't be modified - immutability signals intent and prevents bugs. Dict keys must be hashable - tuples qualify, lists don't because they can change. divmod returns a tuple of (quotient, remainder) - 17 / 5 is 3 remainder 2. The star operator collects remaining items into a list, not a tuple. Use a tuple when the data won't change - a list when you need to add, remove, or reorder.

Common mistakes: Python can swap in one line: no temp variable needed. Lists can't be dict keys (mutable). Use a tuple.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a journey and assign it to your class.

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
return x, y what does this return?
A tuple (x, y)Two separate values
Matches
❌ a, b, c = (1, 2)
Error: Not enough values to unpack
Applying
Meanings
Term
return a, b
Meaning
Returns multiple values from a function as a tuple.
Practice
def min_max(nums):
Testing
Gaps
def minmax(nums):
Check Answer
Spots
2b = 2
3temp = a

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Mantis Shrimp' badge — Speed Striker, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. return x, y what does this return?
A. A tuple (x, y) ✓
B. Two separate values
Returning multiple values with commas automatically packs them into a tuple
2. a, b = b, a what does this do?
A. Sets both to b
B. Swaps a and b ✓
Python evaluates the right side first as a tuple, then unpacks - a clean swap with no temp variable
3. Why use tuples for coordinates?
A. Coordinates shouldn't change ✓
B. Tuples are faster
A point (x, y) shouldn't be modified - immutability signals intent and prevents bugs
4. d = {(0,0): 'origin'} why use a tuple key?
A. It's shorter
B. Tuples are hashable (lists aren't) ✓
Dict keys must be hashable - tuples qualify, lists don't because they can change
5. result = divmod(17, 5)\nresult is?
A. (3, 2) quotient and remainder ✓
B. 3.4
divmod returns a tuple of (quotient, remainder) - 17 / 5 is 3 remainder 2

Match the Pairs

a, b, c = (1, 2) Error: Not enough values to unpack
t[0] = 99 Error: Cannot modify tuple items
a, b = b, a Valid: Swap two values with tuple unpacking
return x, y Ok: Return multiple values as a tuple
(3, 1, 4).index(1) Output: 1
max((2, 8, 5)) Output: 8

Key Term

return a, b
Returns multiple values from a function as a tuple.~~a, b = b, a

Fill in the Blanks

1. def min_max(nums): return min(nums), max(nums)
2. a, b = b, a # swap
3. grid = {} grid[(0,0)] = 'start'
4. first, *rest = (1, 2, 3, 4)
5. _, value = ('key', 42)

Spot the Error

Question 1
A a = 1
B b = 2
C temp = a
D a = b
E b = temp
Line C — Python can swap in one line: no temp variable needed
Question 2
A d = {}
B d[[0, 0]] = 'origin'
C print('Origin:', d[(0, 0)])
D print('Done')
Line B — Lists can't be dict keys (mutable). Use a tuple.
Question 3
A # Function returns 3 values
B name, age = get_user()
C print('Name:', name)
D print('Age:', age)
Line B — Function returns 3 values but only 2 variables: must match
Question 4
A # Capture remaining values
B first, rest = (1, 2, 3, 4)
C print('First:', first)
D print('Rest:', rest)
Line B — Need * before rest to capture multiple remaining values
Question 5
A # Unpack a pair
B a, b, c = (1, 2)
C print('a:', a, 'b:', b)
D print('Done')
Line B — 3 variables but only 2 values: ValueError
For Teachers

Create a free class, add this module to a journey, and track who's stuck.

Create a free teacher account →

No credit card. No setup fee. Make a class and invite students in under three minutes.

For Students

Practice this topic interactively, track progress, and unlock badges.

Start Learning Free →

Have a class code?