Skip to content
Tuple Methods

count()

Count the total occurrences of a specific item in a tuple.

tuple.count(value)

tuple.count() scans the tuple from start to finish and returns the number of times value appears.

Because tuples are immutable, count() does not modify the tuple and works efficiently with any hashable or non-hashable item.

Parameters

NameDescription
valueThe item to search for and count in the tuple.

Returns

An integer representing the number of occurrences (0 if not found).

Try it

Run it and change it
grades = ("A", "B", "A", "C", "A", "B")
print("Count of A:", grades.count("A"))
print("Count of D:", grades.count("D"))

Worth knowing

  • Non-existent items: If the item is not present, count() returns 0 without raising an error.
  • Equality comparison: Uses Python's standard equality (==), meaning 1 and True or 0 and False are treated as equal.

Related entries