A.6 Tuples
A tuple is a sequence of elements of potentially mixed types. A tuple typically contains unordered, heterogeneous elements akin to a struct in C with the exception that a tuple is indexed by numbers (like a list) rather than by field names (like a struct). Formally, a tuple is an element e of a Cartesian product of a given number of sets: e ∈ (S1 × S2 × … × Sn). A two-element tuple is a called a pair [e.g., e ∈ (A × B)]. A three-element tuple is a called a triple [e.g., e (A × B × C)].
The difference between lists and tuples in Python, which has implications for their usage, can be captured as follows. Tuples are a data structure whose fields are unordered and have different meanings, such that they typically have different types. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access