📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Tuples

Tuples

4 min read
Tuples are like lists but immutable: (1, 2, 3). Use tuple unpacking: a, b = (1, 2). Tuples are hashable so they can be dictionary keys. Use them for fixed data that should not change after creation.

Tuples — Immutable Lists

point = (3, 7)
x, y = point         # unpacking
print(x, y)         # 3 7

coords = (1.5, 2.8, -3.0)
print(coords[0])    # 1.5
# coords[0] = 5    # TypeError — immutable!

# Tuple with one item
singleton = (42,)   # note the comma