Python Core



Admission Enquiry Form


Tuple methods in python

Python has two built-in methods that you can use on tuples


Example of count() method in list

count() method returns the number of occurences of a particular element in tuple

tup=(10,20,30,40,20,30,20,50)
cnt=tup.count(20)
print(cnt)


Output:

3




Example of index() method in list

The index() method returns the position at the first occurrence of the specified value.

tup=(10,20,30,40,50)
pos=tup.index(30)
print(pos)


Output:

2