← All lessons

Lesson 13

Tuples & Unpacking

A tuple groups values in order and cannot be modified in place. Commas create the tuple; parentheses often make it clearer.

Unpacking binds several names at once. The number of names must match the number of values unless a starred target gathers extras.

Tuples are useful for fixed records such as coordinates. Immutability does not prevent a mutable object inside a tuple from changing.

point = (4, 7)
x, y = point
print(x + y)

Check your understanding

Which value is a one-item tuple?

CHALLENGE

Unpack ("Ada", 36) into name and age. Print Ada: 36 using an f-string.

Practice →
Next: Indexes with enumerate →