all Python 3Tuples (tuple)term
len/min/max/sum for tuples
aggregation
The built-in functions work with tuples exactly as they do with lists.
Syntax
len(t) | min(t) | max(t) | sum(t)
len on a tuple is O(1) because the length is stored, whereas min, max and sum each walk every element, so calling them one after another means several passes over the same data. On an empty tuple sum quietly returns 0, but min and max raise ValueError.
Examples
t = (3, 1, 4, 1, 5, 9, 2, 6)
print(len(t))
# → 8
print(min(t))
# → 1
print(max(t))
# → 9
print(sum(t))
# → 31
See also
Open in the full glossarydocs.python.orgReport an inaccuracy