✦ Python Foundations Collections module

Concept 09 · Tuples

Keep values together.
Keep their positions fixed.

Lists are useful when a collection needs to grow or change. Tuples keep a fixed group of related values together.

01 Learn02 Try03 Predict

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

A tuple keeps a fixed group of related values together.

You already know lists, indexes, and list operations. A list is a collection whose contents can change; a tuple is a fixed group of values that belong together. Use a list for changing data, such as colors = ["red", "green", "blue"]. Use a tuple for one stable whole, such as point = (10, 20).

coordinates = (45.26, 19.83)

print(coordinates[0])
print(coordinates[1])

A tuple usually uses comma-separated values, often inside (). Its values are ordered items with familiar positions: index 0 selects the first item and index 1 selects the second. Indexing works just as it did for lists.

45.26 19.83

The important difference is that a tuple is immutable: you can read, index, and unpack it, but you cannot replace an existing item. This makes tuples useful for stable groups such as coordinates, a date value, or an RGB color.

↳

Choose by intent: Use a list when items need to be added, removed, or replaced. Use a tuple when values form one fixed group, their positions have meaning, and you do not intend to replace individual items.

Unpacking matches tuple values to variable positions
coordinates = (45.26, 19.83)

latitude, longitude = coordinates

print(latitude)
print(longitude)

Python matches tuple values to variables by position: the first value goes to latitude and the second goes to longitude. The number of values and variables must match, so x, y = point works for point = (10, 20), while x, y, z = point does not.

An existing tuple item cannot be replaced
coordinates = (45.26, 19.83)
coordinates[0] = 50

This raises TypeError. The tuple can be read, indexed, and unpacked, but its existing items cannot be replaced with assignment.

Changing an unpacked variable does not change the tuple
point = (10, 20)

x, y = point
x = 99

print(point)
print(x)

x first receives the value 10. After x = 99, the name x refers to 99; it does not reach back and change point. The tuple is still (10, 20), just as assignment in the Variables lesson changes what a name refers to.

A one-item tuple needs a comma
not_a_tuple = (5)
one_item_tuple = (5,)

The comma creates the one-item tuple. (5) is only the value 5 inside parentheses, while (5,) is a tuple containing one item.

Trace indexing, unpacking, and assignment
point = (4, 7)

print(point[0])

x, y = point
x = 10

print(x)
print(y)
print(point)

Pause before running it. point[0] is 4; unpacking gives x the value 4 and y the value 7. Then x = 10 changes only that variable. The final output is 4, 10, 7, and (4, 7).

Common beginner mistakes

  • Treating a tuple like a mutable listpoint[0] = 5 raises TypeError because an existing tuple item cannot be replaced.
  • Thinking parentheses alone make a one-item tuple(5) is the value 5; (5,) is a one-item tuple.
  • Unpacking into the wrong number of variablesA two-value tuple needs two receiving variables. Python cannot match x, y, z to (10, 20).
  • Thinking an unpacked variable changes the tupleChanging x after x, y = point changes the name x, not the original tuple.

Python Playground

Loading Python runtime…

Before running the code, predict which tuple item an index selects. Then unpack the tuple, change one unpacked variable, and confirm that the original tuple stays the same.

tuples.pyPython
OutputWaiting for Python
The browser runtime is loading. You can still edit the example code.

Pyodide runs Python in a browser Web Worker. It is stopped and restarted if code keeps running. Browser execution is not a complete security boundary; do not enter secrets or rely on it for untrusted code isolation.

What will this program print?

Unpacking gives x and y their values; assigning x later does not replace a tuple item.

point = (4, 7)
x, y = point
x = 10

print(point)
print(x)
Choose the output
Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.