Syncing account progress…

Back

Intermediate · 10 min

Tuples and unpacking

Use fixed groups of values and unpack them into clear names.

Keep values together

A tuple is an ordered collection that cannot be changed after creation. It is useful for a small fixed record such as a coordinate.

point = (4, 7)
print(point[1])

Output

7

Unpack by position

Unpacking assigns each tuple item to a variable in one step. The number of names must match the number of items.

name, score = ("Mina", 92)
print(f"{name}: {score}")

Output

Mina: 92

Tuples and unpacking

  1. Read both tuples and unpacking examples before answering.
  2. Run the task, compare its exact output, and revise the code if needed.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Unpack a booking

Unpack booking into guest, nights, and room. Display Ada stays 3 nights in 204.

Practice