Python String rfind() Method is another inbuilt function in Python Programming that is responsible to return the copy of all the string where each occurrence of the substring has been necessarily replaced for another substring. The replace() method in Python String thus replaces the specific phrase with some other specified phrase. The Python string replace() method also does not change the original string
Following is the syntax for rfind() method:
obj.rfind(str, beg=0 end=len(string))
- str − This specifies the string to be searched.
- beg − This is the starting index, by default its 0.
- end − This is the ending index, by default its equal to the length of the string.
This method returns the last index if found and -1 otherwise.
The example below shows the usage of rfind() method.
str1 = "this is really a string example....wow!!!";
str2 = "is";
print str1.rfind(str2, 0, 10)
print str1.rfind(str2, 10, 0)
print str1.find(str2, 0, 10)
print str1.find(str2, 10, 0)
When the above program is run, then it produces the following result:
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.