Python 3 reference · Tuple Methods
Python Tuple count() Method
Return how many times a value appears in the tuple, comparing each item with ==. Returns 0 if it never appears.
Python 3 Since 3.0
Syntax
tuple.count(value)
Parameters
| Parameter | Description |
|---|---|
value |
The value to count. |
Return value
An int.
Examples
rolls = (6, 2, 6, 6, 1)
print(rolls.count(6), rolls.count(3))
Output
3 0
point = (0, 0, 1)
print(point.count(0) == 2)
Output
True
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
tuple.index()· Return the position of the first item equal to a value. Raises ValueError if it isn't in the tuple.list.count()· Return how many times a value appears in the list, comparing each item with ==. Returns 0 if it never appears.- Python Tuples · tutorial