Primary
tuple() ⚬ᵖʸ|Documentation|1st|20251126180901-00-⌔
Built-in Types — Python 3.14.0 documentation#tuple
class
tuple(iterable=(),/)Tuples may be constructed in a number of ways:
- Using a pair of parentheses to denote the empty tuple:
()- Using a trailing comma for a singleton tuple:
a,or(a,)- Separating items with commas:
a, b, cor(a, b, c)- Using the
tuple()built-in:tuple()ortuple(iterable)The constructor builds a tuple whose items are the same and in the same order as iterable ’s items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a tuple, it is returned unchanged. For example,
tuple('abc')returns('a', 'b', 'c')andtuple([1, 2, 3])returns(1, 2, 3). If no argument is given, the constructor creates a new empty tuple,().Note that it is actually the comma which makes a tuple, not the parentheses. The parentheses are optional, except in the empty tuple case, or when they are needed to avoid syntactic ambiguity. For example,
f(a, b, c)is a function call with three arguments, whilef((a, b, c))is a function call with a 3-tuple as the sole argument.Tuples implement all of the common sequence operations.
Tuples are generic over the types of their contents. For more information, refer to the typing documentation on annotating tuples.
For heterogeneous collections of data where access by name is clearer than access by index,
collections.namedtuple()may be a more appropriate choice than a simple tuple object.Printed 2026-06-28.
Link to original
Secondary
• • •