Python3 rfind () method
description
Python rfind () returns the position of the last occurrence of the string, if there is no match -1 is returned.
grammar
rfind () method syntax:
str.rfind(str, beg=0 end=len(string))
parameter
- str - the search string
- beg - Find the location, the default is 0
- end - the end find a location, the default is the length of the string.
return value
It returns the position of the last occurrence of the string, if there is no match -1 is returned.
Examples
The following example shows rfind () function to use:
#!/usr/bin/python3 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))
Examples of the above output results are as follows:
5 5 -1 2 2 -1