Fill in

Tuples & Unpacking

A tuple is like a list that can never change. It uses round brackets and is perfect for small, fixed groups like coordinates:

camp = (4, 7)
print(camp[0])   # 4
# camp[0] = 5    -> TypeError: tuples can't be changed

Unpacking

You can split a tuple (or list) into separate variables in one go:

x, y = camp       # x is 4, y is 7
a, b = b, a       # swap two variables!

Unpacking also works in a for loop over a list of pairs:

for name, age in [("Ada", 12), ("Bo", 11)]:
    print(name, "is", age)

Assignment

Replace every ___:

  1. Unpack camp into variables x and y.
  2. Swap a and b in a single line.
  3. Loop over shop, unpacking each pair into item and price.