Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
A list is mutable and used for collections that change; a tuple is immutable, hashable if its items are, and used for fixed records or as dictionary keys.
Lists support adding, removing and changing items in place, so they suit collections whose size or contents change. Tuples cannot be changed after creation, which makes them safe to share, slightly lighter in memory, and usable as dictionary keys or set members when all their elements are hashable. By convention, a list holds many items of the same kind, while a tuple often holds a fixed structure of different fields, like a coordinate (x, y) or a row returned from a database. A tuple containing a list is still immutable at the tuple level, but the inner list can change.