Python rfind() method
Description
Python rfind() returns the last position at which a string occurs, or -1 if there is no match.
Syntax
Syntax of the rfind() method:
str.rfind(str, beg=0, end=len(string))
Parameters
- str -- the string to find
- beg -- the position to start searching from, defaulting to 0
- end -- the position to end searching, defaults to the length of the string.
Return Value
Returns the position of the last occurrence of the string, or -1 if there is no match.
Example
The following example shows how to use the rfind() function:
Example
#!/usr/bin/python
str
=
"this is really a string example....wow!!!"
;
substr
=
"is"
;
str
.
rfind
(
substr
)
;
str
.
rfind
(
substr
,
0
,
10
)
;
str
.
rfind
(
substr
,
10
,
0
)
;
str
.
find
(
substr
)
;
str
.
find
(
substr
,
0
,
10
)
;
str
.
find
(
substr
,
10
,
0
)
;
The output of the above example is:
5
5
-1
2
2
-1
Python Strings