Skip to content
String Methods

rindex()

Find the last position of some text and raise an error if it is missing.

str.rindex(sub, start=0, end=len(str))

Find the last position of some text and raise an error if it is missing.

Parameters

NameDescription
subThe text to look for.
startOptional starting position.
endOptional position where the search stops.

Returns

The highest index where the text occurs.

Try it

Run it and change it
text = "banana"
print(text.rindex("na"))

Worth knowing

  • rindex() raises ValueError if the text is missing, while rfind() returns -1.

Related entries