List Methods
list.index()
Finds the first matching element within optional slice-style start and stop bounds, returning its index relative to the original list. The stop bound is exclusive. Negative and out-of-range bounds are normalized; absence raises ValueError, not -1. Matching uses identity or equality and does not require hashable values. Arguments are positional-only; omitted stop searches to the end of the list.
Formal Syntax & Structure
python syntaxpython
items.index(value[, start[, stop]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value | object | Object to add or search for. |
| start | integer-like | Inclusive lower search bound; defaults to zero. |
| stop | integer-like | Exclusive upper search bound; defaults to the end of the list. |
Return Value
int
Zero-based position in the full list of the first matching element.
Working Example
Example Snippetpython
labels = ["draft", "review", "draft", "done"]print(labels.index("draft"))print(labels.index("draft", 1))try: labels.index("missing")except ValueError: print("not found")