List vs tuple: mutability, semantics, and trade-offs
A list is a mutable sequence: you can add, remove, or replace elements in place. A tuple is an immutable sequence: once built, its element references cannot be changed. The deeper reason tuple exists is semantic and operational: immutability makes it hashable when all elements are hashable, so it can be used as a dict key or set member, and it signals a fixed record-like structure. CPython also stores tuples slightly more compactly because it does not need overallocation for growth.
Choose a list for homogeneous, growing/shrinking collections, queues/stacks at the end, or when in-place updates are expected.
Choose a tuple for fixed records, multiple return values, dict keys, set members, and read-only configuration.
Trade-off: namedtuple/dataclass can be clearer than a raw tuple for record semantics; dataclass gives mutability control and methods, namedtuple keeps tuple behavior.
Common mistake: thinking tuple immutability is deep. A tuple can contain a list, and that list can still be mutated.
Version note: dict/set key hashability depends on all tuple elements being hashable; this is not version-specific, but tuple memory/overallocation details are CPython implementation details.
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience