Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python Tuple count()
In this tutorial, you will learn about the Python Tuple count() method with the help of examples.
The tuple count() method returns the number of times a specified item appears in the tuple. It's similar to the list's count() method. Here's a quick example:
models = ('Claude', 'ChatGPT', 'Gemini', 'ChatGPT')
count = models.count('Gemini')
print(f'Count of Gemini: {count}')
count = models.count('ChatGPT')
print(f'Count of ChatGPT: {count}')
Output
Count of Gemini: 1 Count of ChatGPT: 2
count() Syntax
The syntax of count() is:
result = my_tuple.count(item)
Arguments
count() takes a single argument, the item whose count is to be found.
Return Value
count() returns an integer (the number of times the item appears).
Example: Tuple count()
vowels = ('a', 'e', 'i', 'o', 'i', 'u')
count = vowels.count('i')
print(f'Count of i is: {count}')
count = vowels.count('b')
print(f'Count of b is: {count}')
Output
Count of i is: 2 Count of b is: 0
Did you find this article helpful?