rfind() method in Python returns the highest index of a substring in a string.
str.rfind(substring, start, end)
One substring must be passed as a parameter, which is searched for in the string upon calling the method.
The search can be limited to indices specified by the
end parameters. The default value for
0, while the default value for
end is the end of the string.
If the substring is found, the method returns the highest index of that substring’s occurrence in the string.
-1 is returned if the substring does not exist in the given string.
string = "This is a string" x = string.rfind('a') print(x)
string = "This is a string" x = string.rfind('i', 1, 4) print(x)
string = "This is a string" x = string.rfind('z') print(x)
View all Courses