Python
Python SciPy Tutorial: Learn with Example
SciPy in Python SciPy in Python is an open-source library used for solving mathematical,...
The count() is a built-in function in Python. It will return the total count of a given element in a list. The count() function is used to count elements on a list as well as a string.
In this Python tutorial, you will learn:
The count() is a built-in function in Python. It will return you the count of a given element in the list.
list.count(element)
element: The element you want to find the count.
The count() method will return an integer value, i.e., the count of the given element from the given list. It returns a 0 if the value is not found in the given list.
Following example shows the working of count() function on a list:
list1 = ['red', 'green', 'blue', 'orange', 'green', 'gray', 'green']
color_count = list1.count('green')
print('The count of color: green is ', color_count)
Output:
The count of color: green is 3
list1 = [2,3,4,3,10,3,5,6,3]
elm_count = list1.count(3)
print('The count of element: 3 is ', elm_count)
Output:
The count of element: 3 is 4
SciPy in Python SciPy in Python is an open-source library used for solving mathematical,...
What is Python readline? Python readline() is a file method that helps to read one complete line...
Calendar module in Python has the calendar class that allows the calculations for various task...
In Python, there is no need for importing external library to read and write files. Python...
What is Python Enumerate? Python Enumerate() is a buit-in function available with the Python...
What is PyQt? PyQt is a python binding of the open-source widget-toolkit Qt, which also functions as...