Python 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/python str = "this is really a string example....wow!!!"; substr = "is"; print str.rfind(substr); print str.rfind(substr, 0, 10); print str.rfind(substr, 10, 0); print str.find(substr); print str.find(substr, 0, 10); print str.find(substr, 10, 0);
Examples of the above output results are as follows:
5 5 -1 2 2 -1