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
| Name | Type | Description |
|---|---|---|
| value | object | Value to locate using identity or equality. |
| start | integer | Inclusive lower search bound; defaults to zero. |
| stop | integer | Exclusive 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))