List Methods
count()
Count the number of times a value appears in the list.
list.count(value)
list.count() returns the number of times value occurs in the list.
It performs an O(n) linear scan of the list elements using standard equality comparison.
Parameters
| Name | Description |
|---|---|
| value | The value to search for and count. |
Returns
The integer count of matching elements (0 if absent).
Try it
Run it and change it
scores = [95, 80, 95, 70, 95, 85]
print("Count of 95:", scores.count(95))
print("Count of 100:", scores.count(100))Worth knowing
- Safe query: Does not raise an exception if the item is absent, returning
0.