Easy Tutorial
❮ Python Att Time Mktime Html Ref Math Comb ❯

Python3 rfind() Method

Python3 Strings


Description

The Python rfind() method returns the last occurrence of the specified substring within the string. If no match is found, it returns -1.

Syntax

The syntax for the rfind() method is:

str.rfind(str, beg=0, end=len(string))

Parameters

Return Value

Returns the last occurrence of the specified substring within the string. If no match is found, it returns -1.

Example

The following example demonstrates the use of the rfind() method:

#!/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

❮ Python Att Time Mktime Html Ref Math Comb ❯