Tuple Methods

tuple.count()

Scans the tuple and counts matching elements. Identity or equality can establish a match; the search value need not be hashable. A missing value gives zero. Tuple slots cannot be modified, but referenced mutable values can change between calls. Custom equality methods may raise or have side effects. Ordinary counting scans all elements.

Formal Syntax & Structure

python syntaxpython
items.count(value, /)

Parameters & Attributes

NameTypeDescription
valueobjectValue to locate using identity or equality.

Return Value

int

Number of matches, including zero.

Working Example

Example Snippetpython
codes = ("ok", "retry", "ok", "done")print(codes.count("ok"))print(codes.count("missing"))print(([1], [1], [2]).count([1]))
Python Reference