Tuple just likes list, is an object used to group together related data in python. The difference between tuple and list is that the data inside tuple cannot be changed whereas the data in the list can be changed after that list object has been declared.

In this tutorial, we are going to create the python program which will search for the index position (starting from 0) of a certain element within that tuple and count the number of times that element appears within that tuple object.

We will declare the elements within that tuple like this.

student = "a", "b", "c", "a", "a"

Or this.

student = ("a", "b", "c", "a", "a")

Next we will count the total number of the “a” element within the above tuple.

totala = student.count("a")
print(totala) # output 3

Finally let us look for the position of the “a” element within the range of index position number 2 until but not include index position number 4.

print(student.index("a", 2, 4)) # output 3

Python tuple does not have many methods and the above two methods are the most important one.

Please follow and like us:

Leave a Reply

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