Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 rfind() Method

Python3 rfind() Method

Python3 Strings Python3 Strings


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

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"

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

)

)

The output of the above example is:


5
5
-1
2
2
-1

Python3 Strings Python3 Strings