What is the list count() Method?
list count() function in Python is a built-in function that lets you count the occurrence of an element in a list. It returns the count of how many times an element is present in a list.
It has various applications depending on how you use it. For example: If the count of any element is greater than 1 that means there are duplicate values. If count is 0 that means the element is not present in the list. So depending on how you use it, it can have different uses.
It only accepts one parameter, if you pass more than one parameter it raises TypeError.
Python List count() method
Python List count() method returns the count of the occurrences of a given element in a list.
Example:
Python3
#create a list fruits = [ "Apple" , "Mango" , "Banana" , "Cherry" , "Papaya" ] # printing count using count() function print (fruits.count( "Apple" )) |
1