Skip to content
String Methods

rfind()

Find the last position of some text without raising an error when it is missing.

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

Find the last position of some text without raising an error when it is missing.

Parameters

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

Returns

The highest index, or -1 if the text is not found.

Try it

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

Worth knowing

  • rfind() searches from the right for the last match; find() returns the first match.

Related entries