list.index
Find the first item of the list that equals x.
Python 3.13
list.index(x[, start[, end]])Parameters
- xAny
- The value to search for.
- startintoptional
- The index where the search starts.
- endintoptional
- The index before which the search stops.
Return value
The index of the first matching item; raises ValueError if there is none.
Examples
Position of an item in a list
Python 3.13
print([1, 2, 3].index(2))1
Searching from a given position
Python 3.13
a = ['a', 'b', 'a']
print(a.index('a', 1))2
Details
If the item may be missing, check for it first: x in a.
