Home >>Python Tuple Methods >Python Tuple index() Method

Python Tuple index() Method

Python Tuple index() Method

Python index() method is used to find the first occurrence of the specified value in the given input tuple. It raises an exception if the specified value is not found.

Syntax:
tuple.index(value)

Parameter Values

Parameter Description
value This is a required parameter. It defines the item to search for.
Here is an example of Python index() method:

thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8)
print(x)

Output:
3
Example 2:

a = ['Abhi', 'Mickey', 'Jerry', 'Abhi', 'Cobra', 'Alpha', 'Abhi']
X = a.index("Jerry")
print(X)

Output:
2

No Sidebar ads