Python tuple count()

Python list‘s count method returns count of elements in the tuple.


Here tuple1 is object of the tuple and item is the element you want to count in the tuple.


returns number of occurences of the element in the tuple


Let’s see a very simple example:

tupleOfCountries=('India','Bhutan','India','China','Nepal') print("Count of India in tuple:",tupleOfCountries.count('India')) print("Count of USA in tuple:",tupleOfCountries.count('USA'))


Count of India in tuple: 2
Count of USA in tuple: 0

Let’s see how to get count of set which is inside the tuple.

tuple1=('One','two',{10,20,30},'three','four',{10,20,30}) count=tuple1.count({10,20,30}) print("Count of set in tuple:",count)


Count of set in tuple: 2

That’s all about Python tuple count() method.

Leave a Reply

Your email address will not be published. Required fields are marked *