Python rindex () method
description
Python rindex () returns the position of substring in string str the last occurrence, if no matching string reported abnormal, you can specify the optional parameter [beg: end] with discovery interval.
grammar
rindex () method syntax:
str.rindex(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
Returns the position of substring in string str the last occurrence, if no matching string reported abnormal.
Examples
The following example shows rindex () function to use:
#!/usr/bin/python str1 = "this is string example....wow!!!"; str2 = "is"; print str1.rindex(str2); print str1.index(str2);
Examples of the above output results are as follows:
5 2