Contents
- Introduction
- Syntax count[]
- Example 1: Count occurrences of Item in Python List
- Summary
Count Items in List with a Given Value
To count the number of occurrences of items with a specific value in a list, you can call count[] function on the list with the specific item passed as argument to the count[] function.
Syntax count[]
Following is the syntax of count[] function.
count[] function returns the number of occurrences of the item in this list.
Example 1: Count occurrences of Item in Python List
In the following example, we will create a list and find the number of occurrences of some of the items in the list.
Python Program
Output
74 occurred 2 times in the list. 62 occurred 3 times in the list. 92 occurred 1 times in the list.The count[] function takes exactly one argument.
Summary
In this tutorial of Python Examples, we learned how to count the number of times an item is present in a given list.
Related Tutorials
- Python List with First N Elements
- Python List of Strings
- Python Program to Find Smallest Number in List
- How to Check if Python List is Empty?
- Python List of Dictionaries
- How to Reverse Python List?
- Python List of Functions
- Python Program to Find Largest Number in a List
- How to Append List to Another List in Python? list.extend[list]
- How to Get the list of all Python keywords?