Python List: count() Method
count() Method
The count() method is used to get the number of times a specified element appears in a given list.
Visual Explanation:

Syntax:
list.count(element)
Parameter:
- element - Required. The element is to be counted.. Type -> any type (string, number, list, tuple, etc.).
Return value from count() method
The number of times an element appears in the list is returned.
Example 1: Use of count() method
# colors list
colors = ['Red', 'Green', 'Black', 'Red', 'Green']
print("Original list:")
print(colors)
print("Number of times the value 'Red' appears in the colors list:")
ctr = colors.count("Red")
print(ctr)
Output:
Original list: ['Red', 'Green', 'Black', 'Red', 'Green'] Number of times the value 'Red' appears in the colors list: 2
Example 2: Count tuple and list elements inside list
nums = [[1,2], [1,2,3], [3,4,5], [1,2]]
print("Original list:")
print(nums)
print("Number of times the list '[1,2]' appears in the said list:")
ctr = nums.count([1,2])
print(ctr)
Output:
Original list: [[1, 2], [1, 2, 3], [3, 4, 5], [1, 2]] Number of times the list '[1,2]' appears in the said list: 2
Python Code Editor:
Previous: Python List copy() Method.
Next: Python List extend() Method.
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Memory Footprint Of An Object:
import sys x = 'farhadmalik' print(sys.getsizeof(x))
60
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook