Table of Contents
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
1 2 3 |
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.
1 2 3 4 5 6 7 |
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.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.