Tuples in Python are immutable sequences of arbitrary objects. Once created, the objects within them cannot be replaced or removed, and new elements cannot be added.
Tuples have a similar literal syntax to lists, except that they are delimited by parentheses rather than square brackets. Here is a literal tuple containing a string
, a float
and an integer:
>>> t = ("Norway", 4.953, 3) >>> t ('Norway', 4.953, 3)
We can access the elements of a tuple by zero-based index using square brackets:
>>> t[0] 'Norway' >>> t[2] 3
We can iterate over it using a for
-loop:
>>> for item in t: >>> print(item) Norway 4.953 3