Python List count() Method
Example
Return the number of times "cherry" appears in the fruits list:
fruits = ['apple', 'banana', 'cherry'] x = fruits.count("cherry")
Definition and Usage
The count() method returns the number of elements with the specified value.
Syntax
list.count(value)
Parameter Value
Parameter | Description |
---|---|
value | Required. Any type (string, number, list, tuple, etc.). The value to be searched. |
More Examples
Example
Return the number of times the value 9 appears in the list:
points = [1, 4, 2, 9, 7, 8, 9, 3, 1] x = points.count(9)