Python Tuple index() Method
Example
Search for the first occurrence of the value 8, and return its position:
x = thistuple.index(8)
print(x)
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
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:
x = thistuple.index(8, 5)
print(x)
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:
x = thistuple.index(8, 4, 7)
print(x)