Python List Count

Python List Count

Now, we are going to discuss the count method. Basically, using this method, we get how many times, some element has occurred in the list. We can simply say that it is going to return the count of an element in the list. Let’s have a look at a simple program, which demonstrates the same thing.

As you can see in the above program, we have a simple list, and then we are using the count method on the list. We are trying to count how many times 12 has occurred in the list, and the clear output is 3. you can try executing the program and observing the output as well.

Now, Let’s say that we provide such an argument, which is not at all present in the list, and in such a situation, we get the return value as 0. Let’s have a look at this as well –

As you can see, in the count method, we are providing a value, which is not at all present in the list, and the return value from the count method that we are going to get, is simply 0. You can try observing the output of this program as well. We can use the count method in our program, as and when required.