Python String rfind() Method

Returns the index of the last occurrence found of the specified substring. Python will return -1 if the search string is not found.

Syntax

Python
string.rfind(value, start, end)

Parameters

ParameterDescription
value Required. The string to search for
start Optional. The index in the string at which to start the search. The deffault is None meaning the start of the string.
end Optional. The index in the string at which to stop the search. The default is None meaning the end of the string.

Example

Python
str = 'Hello World'
print(str.rfind('o'))
print(str.rfind('q'))

Output

7
-1