all Python 3Lists (list)function
list.index
search
Return the index of the first matching value; optional start/end narrow the search; raises ValueError if absent.
Syntax
lst.index(value[, start[, stop]])
Unlike str.find there is no "not found" return value: a missing item raises ValueError, so either wrap the call in try or check with in first. The scan is linear and left to right, and with start/end the number you get back is still an index into the whole list, not an offset from start.
Examples
letters = ['a', 'b', 'c', 'b']
print(letters.index('b')) # → 1
print(letters.index('b', 2)) # → 3
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy