Python List count() Method

Returns the number of times the given element occurs in the list.

Syntax

Python
list.count(value)

Parameters

ParameterDescription
value Required. The value to search for within the list. This value can be of any type

Example

Python
groceries = ['apple', 'orange', 'paper towels', 'apple']
numApples = groceries.count('apple')
numOranges = groceries.count('orange')
print(f'We have {numApples} apples and {numOranges} oranges.')

Output

We have 2 apples and 1 oranges.