What is the difference between a list and a tuple, and when should you use each?
Lists are mutable sequences; tuples are immutable. Use a tuple when the collection of items is fixed by meaning — coordinates, RGB values, function return values — and a list when the collection will grow, shrink, or be modified in place. Immutability also makes tuples hashable, so they can serve as dict keys or set members.
How to think about it
How to frame this in an interview
The surface answer is “lists are mutable, tuples are immutable.” A stronger answer adds why that matters in practice: hashability (tuples can be dict keys), slightly lower memory, and the semantic signal you send to other developers — a tuple says “these values belong together and will not change”, which a list does not convey.
Mutability — the dividing line
coords = (40.7128, -74.0060) # tuple — fixed pair: (lat, lon)
coords[0] = 0.0 # TypeError: 'tuple' object does not support item assignment
names = ["Alice", "Bob"]
names.append("Carol") # fine — list is mutable
Hashability — tuples as dict keys
Because a tuple’s contents cannot be reassigned, Python can compute a stable hash for it. This lets you use tuples as dictionary keys or set members — which lists cannot do at all.
grid = {}
grid[(0, 0)] = "origin" # tuple key works
grid[[0, 0]] = "origin" # TypeError: unhashable type: 'list'
This is genuinely useful: grid coordinates, composite cache keys, multi-column lookups.
Interactive demo — see both types in action
When to use which
| Situation | Choose |
|---|---|
| Fixed-meaning record (lat/lon, RGB, DB row) | tuple |
| Return multiple values from a function | tuple |
| Collection that grows or is filtered | list |
| Stack / queue / pipeline of items | list |
| Dict key or set member | tuple |
Memory and speed
Tuples are slightly smaller in memory and faster to construct because Python can intern small tuples and skips the over-allocation that lists use to amortise append costs. For large numerical data, neither is the right choice — use a NumPy array.