Python 3 reference · Tuple Methods

Python Tuple index() Method

Return the position of the first item equal to a value. Raises ValueError if it isn't in the tuple.

Python 3 Since 3.0

Syntax

tuple.index(value, start=0, stop=len(tuple))

Parameters

ParameterDescription
value The value to find.
start, stop optional Only search this slice.

Return value

An int.

Examples

Find a positionTry it yourself
days = ("mon", "tue", "wed")
print(days.index("tue"))

Output

1
Missing values raiseTry it yourself
t = (1, 2)
try:
    t.index(9)
except ValueError:
    print("not found")

Output

not found

Version history

VersionChange
Python 3.0Added