- rfind() is python in-build function which are used to find the index of the substring in the given string.
- if it not find the searching element in given string then it will return location -1.
Syntax-
str.rfind(str1,beg,end)
- here str is given string.
- and str1 is the substring whose index is to be find
- beg and end are the starting and ending point of given string where you want to search.
Difference between find() and rfind() in python-
Basically, both function are used to search the location of the substring in given string but
- find() start searching from the left side of the string
- and rfind() start searching from the right side of the string.
Example
string is s="This is is string"
s.find("is") will give 5
s.rfind("is") will give 8
program-
s="this is is string"
print(s.rfind("is"))
s="Hello program"
print(s.rfind("o"))
s="mytext"
print(s.rfind("m"))
s="mytext"
print(s.rfind("t"))
s="mytext"
print(s.rfind("t",0,3))
8
8
0
5
2