How to Use Count in Python
![how to use count in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-use-count-in-python-1024x576.jpg)
This article covers the topic of how to use count in Python.
The count()
method returns the number of elements with the specified value.
Syntax : list.count(value)
value – Required. This is the value to search for. It can be string, number, list, tuple, etc.
numbers = [1, 3, 2, 8, 3, [1, 2], 6, 1, 8, 5, 3, 8] x = numbers.count(3) p = numbers.count(8) a = numbers.count([1, 2]) print(x, p, a) names = ['rahul', 'abhi', 'abhi'] y = names.count('abhi') print(y)
Output:
3 3 1 2
Subscribe
Login
Please login to comment
0 Discussion