When should you choose a tuple instead of a list?
Answer
Choose a tuple for a fixed-size, heterogeneous, read-only record — such as a coordinate pair or a database row — where immutability communicates intent and prevents accidental mutation, and choose a list for a homogeneous, variable-length collection you plan to grow, shrink or reorder. Tuples are also hashable when their elements are hashable, so they can be used as dict keys or set members, while lists cannot.
Strong answer includes
- tuple for fixed-shape immutable records
- list for growable homogeneous collections
- tuples are hashable and can be dict keys
Practical example
point = (12.4, 55.1)signals a fixed 2D coordinate that should not change shape, while
queue = []signals a collection meant to be appended to and popped from over time.