Data Structures14 min read

Tuple Essentials

Understand tuples clearly: why immutability matters, where tuples are better than lists, and how packing/unpacking works with real examples.

David Miller
December 12, 2025
1.7k65

A tuple is like a list, but immutable (cannot be changed).

When to use tuples

Use tuples when:

  • data should not change (like coordinates)
  • you want safer code (no accidental edits)
  • you want to return multiple values from a function

Create tuples

point = (10, 20)
user = ("Tom", 25, "Austin")

Single-item tuple (common beginner confusion)

x = (5)     # this is int, not tuple
y = (5,)    # this is tuple

Access items

point = (10, 20)
print(point[0])  # 10

Tuple unpacking (very important)

person = ("Sarah", 28)
name, age = person
print(name, age)

Why immutability is useful

If you store config settings, you don’t want changes by mistake.

CONFIG = ("localhost", 5432)
# CONFIG[0] = "prod"  # error, cannot change

Graph: list vs tuple

flowchart LR
  A[List] --> B[Mutable: can change]
  C[Tuple] --> D[Immutable: cannot change]

Remember

  • Tuples are ordered but immutable
  • Great for fixed data
  • Unpacking is a powerful Python skill
#Python#Beginner#Tuple