Python Tuple index() Method
Example
Search for the first occurrence of the value 8, and return its position:
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8)
print(x)
Try it Yourself »
Definition and Usage
The index() method finds the first
occurrence of the specified value.
The index() method raises an exception if the value is not found.
Syntax
tuple.index(value, start, end)
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The item to search for |
| start | Optional. Where to start the search |
| end | Optional. Where to end the search |
More Examples
Example
Using the start parameter: Return the first occurrence of the value 8, starting the search at index 5:
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8, 5)
print(x)
Try it Yourself »
Example
Using the start and end parameters: Return the first occurrence of the value 8, starting the search at index 4, but end the search at index 7:
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8, 4, 7)
print(x)
Try it Yourself »