Python List Count() - Programiz
Maybe your like
Become a certified Python programmer.
ENROLLPopular Tutorials
Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning PythonPopular Examples
Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year Explore Python ExamplesReference Materials
Built-in Functions List Methods Dictionary Methods String Methods View allCreated with over a decade of experience.
- Learn
- Practice
- Compete
Certification Courses
Created with over a decade of experience and thousands of feedback.
Learn Python Learn HTML Learn JavaScript Learn SQL Learn DSA View all Courses onBecome a certified Python programmer.
Try Programiz PRO!Popular Tutorials
Getting Started With Python Python if Statement while Loop in Python Python Lists Dictionaries in Python Start Learning Python All Python TutorialsReference Materials
Built-in Functions List Methods Dictionary Methods String Methods View all Python JavaScript C C++ Java R KotlinBecome a certified Python programmer.
Try Programiz PRO!Popular Examples
Add two numbers Check prime number Find the factorial of a number Print the Fibonacci sequence Check leap year All Python ExamplesPython List Methods
- Python List index()
- Python List append()
- Python List extend()
- Python List insert()
- Python List remove()
- Python List count()
- Python List pop()
- Python List reverse()
- Python List sort()
- Python List copy()
- Python List clear()
Python Tutorials
- Python Tuple count()
- Python String count()
- Python enumerate()
- Python Tuple index()
- Python Iterators
- Python List
Python List count() The count() method returns the number of times the specified element appears in the list.
Example
# create a list numbers = [2, 3, 5, 2, 11, 2, 7] # check the count of 2 count = numbers.count(2) print('Count of 2:', count) # Output: Count of 2: 3Syntax of List count()
The syntax of the count() method is:
list.count(element)count() Parameters
The count() method takes a single argument:
- element - the element to be counted
Return value from count()
The count() method returns the number of times element appears in the list.
Example 1: Use of count()
# vowels list vowels = ['a', 'e', 'i', 'o', 'i', 'u'] # count element 'i' count = vowels.count('i') # print count print('The count of i is:', count) # count element 'p' count = vowels.count('p') # print count print('The count of p is:', count)Output
The count of i is: 2 The count of p is: 0Example 2: Count Tuple and List Elements Inside List
# random list random = ['a', ('a', 'b'), ('a', 'b'), [3, 4]] # count element ('a', 'b') count = random.count(('a', 'b')) # print count print("The count of ('a', 'b') is:", count) # count element [3, 4] count = random.count([3, 4]) # print count print("The count of [3, 4] is:", count)Output
The count of ('a', 'b') is: 2 The count of [3, 4] is: 1Also Read:
- Python Program to Count the Occurrence of an Item in a List
- Python Tuple count()
Sorry about that.
How can we improve it? Feedback * Leave this field blankYour builder path starts here. 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
Python References
Python Library
Python List index()
Python Library
Python List insert()
Python Library
Python List remove()
Python Library
Python List pop()
Tag » How To Get The List Number
-
How Do I Get The Number Of Elements In A List In Python?
-
Python: Get Number Of Elements In A List - Stack Abuse
-
How To Get The Number Of Elements In A Python List? - GeeksforGeeks
-
Get The Number Of Items Of A List In Python - Nkmk Note
-
Python List Index() - Programiz
-
Create A Bulleted Or Numbered List - Microsoft Support
-
Python : Get Number Of Elements In A List, Lists Of Lists Or Nested List
-
Python Count Number Of Elements In List - Full Guide - Stack Vidhya
-
How To Find The Number Of Elements In A List - Python - YouTube
-
Python Find String In List - DigitalOcean
-
How To Convert List To String In Python? Here Are The 6 Ways To Know
-
Python List Count() With EXAMPLES - Guru99
-
Python Unique List – How To Get All The Unique Values In A List Or ...
-
Python List Max() Method - Tutorialspoint