Editor settings

General settings

Save settings

Learn to program with Python

Count an item in a list #

The list.count() method in Python is used to count the number of occurrences of a specific item in a list. It takes a single argument, which is the item to be counted.

For example:

fruits = ['apple', 'banana', 'cherry', 'apple', 'orange', 'apple']
count = fruits.count('apple')
print(count)  # Output: 3

Exercise #

Use the method count() to count the number of "cherry" in the list and assign to the variable count

Tests #

  • Variable count should be the number of "cherry" in the list fruits
  • Use count() function
  • Do not edit the first line of code
Output will be displayed here