Tuple Methods

tuple.index()

Locates the earliest matching element in the selected half-open index interval. Negative bounds are relative to the tuple length and ordinary out-of-range bounds are clipped. The result is a position in the entire tuple. If no match exists in the interval, ValueError is raised, not -1. Values need not be hashable; equality failures may propagate.

Formal Syntax & Structure

python syntaxpython
items.index(value[, start[, stop]])

Parameters & Attributes

NameTypeDescription
valueobjectValue to locate using identity or equality.
startintegerInclusive lower search bound; defaults to zero.
stopintegerExclusive upper search bound; defaults to the tuple length.

Return Value

int

Zero-based position in the original tuple.

Working Example

Example Snippetpython
stages = ("draft", "review", "draft", "done")print(stages.index("draft"))print(stages.index("draft", 1))print(stages.index("review", -3, -1))
Python Reference