In this post, we will see about Python tuple’s count method.Python tuple’s count method is used to count the occurrences of element in the tuple.
Python tuple count syntax
tuple1.count(element)
tuple1 is object of the tuple and element is the object which you want to get count.
Python tuple count example
Let’s understand count method with the example.
t=(1,2,2,3,2,3,2,3,4,2,7,7,5)
print("Count of 2 is:",t.count(2))
tupleOfCounties=('China','India','China','Bhutan')
print("Count of 'China' is:",tupleOfCounties.count('China'))
Output:
Count of 2 is: 5
Count of ‘China’ is: 2
Count of ‘China’ is: 2
That’s all about Python tuple count.