count(value) returns an int: how many items in the list are equal to value. If none are, the answer is 0; it never raises for a missing value. The list is not changed.
Items are compared with ==, so equal numbers match across types: 1, 1.0, and True all count as each other. Only top-level items are checked; count() does not look inside nested lists or inside strings.
list.count() is an instance method of the built-in list type: call it on a list with dot notation, such as votes.count(...). No import is needed.
Syntax
Pass exactly one value to count.
python
n = lst.count(value)
Call
What it does
[1, 2, 1, 1].count(1)
Returns 3.
["a", "b"].count("z")
Returns 0; a missing value is not an error.
[[1, 2], [1]].count(1)
Returns 0: the 1s are inside nested lists, not items of the outer list.
Every call scans the whole list. To count every distinct value at once, collections.Counter(lst) does it in a single pass. To count characters in one string, use str.count() instead.
Method signatures
python
list.count(value)
# returns: int, the number of items equal to value
Parameters
Parameter
Description
value
Any object, compared with each item using ==. It is required: lst.count() with no argument raises TypeError.
Return Value
Return Value
Description
int
The number of matching items, from 0 up to len(lst).
Python Examples
Example 1 — Tally a Team Lunch Poll
Count one dish, a dish nobody picked, and then every dish in alphabetical order.
python
votes = ["pizza", "sushi", "pizza", "tacos", "pizza", "sushi"]
print(votes.count("pizza"))
print(votes.count("burgers"))
for dish in sorted(set(votes)):
print(dish, votes.count(dish))
Output
3
0
pizza 3
sushi 2
tacos 1
How It Works
Exact matches. "pizza" appears three times among the six votes.
Zero, not an error. Nobody voted for burgers, so count() returns 0; compare index(), which would raise ValueError.
Each dish once.set(votes) drops duplicates and sorted() puts the dishes in a fixed alphabetical order for printing.
A small tally. Counting each unique dish gives the full result: 3, 2, and 1.
Example 2 — Draw a Histogram of Product Star Ratings
Count each star level from 5 down to 1 and print a bar of asterisks, then the share of 5-star reviews.
python
ratings = [5, 4, 5, 3, 5, 4, 1, 5, 2, 4]
for stars in range(5, 0, -1):
n = ratings.count(stars)
print(stars, "*" * n, n)
share = ratings.count(5) / len(ratings)
print(f"5-star share: {share:.0%}")