Python Glossary Русский

all Python 3Tuples (tuple)function

tuple.index

methods

Return the index of the first matching value; optional start/end narrow the search; raises ValueError if absent.

Syntax

t.index(value[, start[, stop]])

A missing value raises ValueError — tuples have no forgiving counterpart to str.find() that returns -1, so either wrap the call in try or test value in t first. The start argument only moves where the scan begins; the index you get back is still counted from the beginning of the tuple, not from start.

Examples

t = (10, 20, 30, 20)
print(t.index(20))      # → 1
print(t.index(20, 2))   # → 3

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy