Python 3 reference · List Methods

Python List count() Method

Return how many times a value appears in the list, comparing each item with ==. Returns 0 if it never appears.

Python 3 Since 3.0

Syntax

list.count(value)

Parameters

ParameterDescription
value The value to count.

Return value

An int.

Examples

Count a valueTry it yourself
votes = ["yes", "no", "yes", "yes"]
print(votes.count("yes"), votes.count("maybe"))

Output

3 0
Counting everything: use CounterTry it yourself
from collections import Counter
print(Counter(["a", "b", "a", "c", "a"]).most_common(2))

Output

[('a', 3), ('b', 1)]

Version history

VersionChange
Python 3.0Added