all Python 3Tuples (tuple)function
tuple.count
methods
Return the number of occurrences of a value in the tuple (compared with ==).
Syntax
t.count(value)
Every call walks the whole tuple, O(n), so counting a dozen different values one by one is wasteful — build collections.Counter(t) once instead. Matching uses ==, which means t.count(1) also counts every True in the tuple, and t.count(0) counts every False.
Examples
t = (1, 2, 2, 3, 2)
print(t.count(2)) # → 3
print(t.count(9)) # → 0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy