Python Program to Count the Occurrence of an Item in a List

To understand this example, you should have the knowledge of the following Python programming topics:


Using count() method

freq = ['a', 1, 'a', 4, 3, 2, 'a'].count('a')
print(freq)

Output

3

Using count() method, pass the item to be counted. As shown above, 'a' is passed, which gives the total number of occurrences of character 'a'.


Also Read:

Did you find this article helpful?

Your path to become a builder.

Builders don’t just know how to code, they create solutions that matter. Escape tutorial hell and ship real projects.

Try Programiz PRO
  • Real-World Projects
  • On-Demand Learning
  • AI Mentor
  • Builder Community