Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

list.index

Finds the first identical or equal element at or after the optional start index.

Version: Python 3.14; repository image, production runtime not attested

Syntax

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

Finds the first identical or equal element at or after the optional start index.

Failure raises ValueError. The returned index is relative to the original list, including when a start bound is used.

Compares objects by identity or equality in the selected range, excluding stop. With the start set to one the first 3 is skipped and the second 3 has original zero-based index two. No matching seven raises ValueError.

x = float("nan")
assert x != x and [0, x].index(x) == 1

Examples

a = [3, 5, 3]
print(a.index(3, 1))
try:
    a.index(7)
except ValueError as error:
    print(type(error).__name__)

Result

2
ValueError

Compares objects by identity or equality in the selected range, excluding stop. With the start set to one the first 3 is skipped and the second 3 has original zero-based index two. No matching seven raises ValueError.

Sources