Meet the Tuple: Like a List That Won't Budge
The problem...
You have a list of coordinates. Latitude and longitude. Two values that belong together and should never change.
location = [44.4268, 26.1025]
A list works. But nothing stops someone — including you — from accidentally modifying it.
location[0] = 0 # no error. data corrupted.
Sometimes you need a container that holds its shape. No modifications. No surprises.
The idea!
A tuple is like a list — ordered, indexed, iterable.
With one difference: once you create it, you can't change it.
That's not a limitation. That's the point.
Making it real
Parentheses instead of square brackets. Values separated by commas.
location = (44.4268, 26.1025)
print(location)
Output → (44.4268, 26.1025)
That's a tuple. Two values. Locked in place.
The full picture
A tuple can hold any type — strings, integers, floats, mixed:
soldier = ("Raven", 85, True)
rgb = (255, 0, 0)
point = (10.5, 22.3)
You access elements exactly like a list — with indexes:
soldier = ("Raven", 85, True)
print(soldier[0]) # Raven
print(soldier[-1]) # True
Slicing works too. Looping works too. len(), in, count(), index() — all work.
What doesn't work: anything that tries to change it.
soldier[0] = "Wolf" # TypeError: 'tuple' object does not support item assignment
When to use a tuple
Use a tuple when your data is fixed — when changing it would be a bug, not a feature:
- Coordinates — latitude, longitude
- RGB color values — (255, 0, 0)
- A record that shouldn't change — a date, a database row
- Returning multiple values from a function — Python packs them into a tuple
- Dict keys — tuples can be keys, lists cannot
Use a list when your data needs to grow, shrink, or change.
Use a tuple when it doesn't.
What's really happening
Python treats tuples as immutable — the values are set at creation and cannot be modified, added to, or removed from.
This makes tuples slightly faster than lists and safer to pass around — you know the data won't be touched.
Heads up!
- Parentheses are optional —
a, b = 1, 2creates a tuple - A single-element tuple needs a trailing comma:
(42,)— without it, Python treats it as just a number in parentheses - Tuples are immutable — but if a tuple contains a list, that list can still be modified
The mindset shift
Stop thinking: "A tuple is just a read-only list."
Start thinking: "A tuple is a guarantee — this data is fixed, and I mean it."
What you should understand now
- A tuple stores multiple values in a fixed, ordered container
- Created with parentheses and commas
- Immutable — cannot be changed after creation
- Supports indexing, slicing, looping,
len(),in - Use when data should not change — coordinates, colors, fixed records
- A single-element tuple needs a trailing comma:
(42,)