Junior Codes
The Treasure Archive

Python Tuples and Unpacking for Kids

Group values that belong together and unpack them in one line.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Tuples & unpacking, explained simply

A tuple is like a list that cannot be changed once it is made. You write it with round brackets: spot = (3, 5). It is ideal for values that belong together, like the x and y of a point on a map.

Unpacking lets you pull a tuple apart into separate variables in one go: x, y = spot. The number of names on the left must match the number of values.

Lists of tuples are a handy way to store records, and a for loop can unpack each one as it goes.

Example: Mark the treasure

treasures = [("gold", 2, 4), ("pearl", 6, 1)]
for name, x, y in treasures:
    print(f"{name} is at column {x}, row {y}")

Output

gold is at column 2, row 4
pearl is at column 6, row 1

Try this

  • Swap two variables with a, b = b, a.
  • Try to change spot[0] and read the error.
  • Store three friends as (name, age) tuples and print each one with unpacking.

Practise it in Wonderwild

“Draw the treasure chart”

Mission 24 in The Treasure Archive, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Why use a tuple instead of a list?+

A tuple signals that the group should not change, which protects it from accidental edits. Tuples can also be used as dictionary keys, which lists cannot.

What happens if the unpacking numbers do not match?+

Python raises a ValueError saying there are too many or not enough values to unpack.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course