tuple

An ordered, fixed-length group of values in which each position can have its own meaning and type.

In more detail

Many languages have tuples: Python writes them in round brackets, such as (250, 2), while TypeScript and Terraform have tuple types such as [string, number] and tuple([string, number]). Unlike a list, a tuple's length is part of what it is. Python tuples cannot be changed once made, so they can be dictionary keys, and they are compared element by element from the left.

Examples

(x, y) as a dict key; (priority, task) as a heap entry; (neighbour, weight) for a weighted edge.
The course's serializer keeps its public field names in a tuple, so a new column stays private until someone adds it there.
kafka-python header: ('content-type', b'application/json')
('content-type', b'application/json')
The course's tuple trap: Line((1, 2), (3, 4)) fails because graphics.py wants Point objects, not tuples.
point = (3, 4)
x, y = point
React hooks return tuples such as [value, setValue] when callers usually rename the parts.
const [isPending, startTransition] = useTransition();
In Terraform a tuple is a structural type, such as tuple([string, number]). A literal list like ["a", 1] is a tuple until it is converted to a list type.
In this course: The course represents each basket line as a tuple of price in pence and count. pytest's parametrize takes a list of tuples, one tuple per test case, in the same order as the parameter names.

Related terms

Taught in

References

Certification courses