Python3 rfind() Method
Description
Python rfind() returns the position of the last occurrence of a string, 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, defaults 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/python3
str1
=
"this is really a string example....wow!!!"
str2
=
"is"
(
str1.
rfind
(
str2
)
)
(
str1.
rfind
(
str2
,
0
,
10
)
)
(
str1.
rfind
(
str2
,
10
,
0
)
)
(
str1.
find
(
str2
)
)
(
str1.
find
(
str2
,
0
,
10
)
)
(
str1.
find
(
str2
,
10
,
0
)
)
The output of the above example is:
5
5
-1
2
2
-1
Python3 Strings