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

Python rfind() method

Python rfind() method

Python Strings Python Strings


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

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"

;

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

)

;

The output of the above example is:



5

5

-1

2

2

-1


Python Strings Python Strings