Python String rfind() Method is another inbuilt function in Python Programming that is responsible to return the copy of all the strings 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))
This method returns the last index if found and -1 otherwise.
The example below shows the usage of rfind() method.
#!/usr/bin/python str1 = "this is really a string example....wow!!!"; str2 = "is"; print str1.rfind(str2) print str1.rfind(str2, 0, 10) print str1.rfind(str2, 10, 0) print str1.find(str2) print str1.find(str2, 0, 10) print str1.find(str2, 10, 0)
When the above program is run, then it produces the following result:
5 5 -1 2 2 -1
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.