Python List count() Method Tutorial

In this section, we will learn what the List count() method is and how to use it in Python.

What is Python List count() Method?

The Python List count() method is used to see how many times a value appeared as an element of a list.

Basically, this method takes the target value as its argument and search for it in the target list. Finally, it will return the number of times that value appeared on the list.

List count() Method Syntax:

list.count(value)

List count() Method Parameter:

The method takes one argument and that is the value we want to search for in the target list to see how many times it was used as an element in that list.

List count() Method Return Value:

The return value of this method is an integer declaring the number of times the target value appeared as an element in a list.

Example: python count elements in list

li = ["ItemOne","ItemTwo","ItemThree","ItemOne","ItemTwo","ItemThree"]

print(li.count("ItemOne"))

Output:

2

As you can see, because the “ItemOne” value appeared two times in the list, so calling the count() method on this value returned the value 2.

Leave a Reply