Javatpoint Logo
Javatpoint Logo

Python String rfind() Method

Python rfind() method finds a substring in in the string and returns the highest index. It means it returns the index of most righmost matched subtring of the string. It returns -1 if substring not found.

Signature

Parameters

sub : substring to be searched.

start (optional) : starting index to start searching.

end (optional) : end index where to search stopped.

Return

It returns either index of substring or -1.

Let's see some examples of rfind() method to understand it's functionality.

Python String rfind() Method Example 1

Let's have a simple example to implement the rfind() method. It returns highest index of the substring.

Output:

16

Python String rfind() Method Example 2

One more example to understand the working of rfind() method.

Output:

18

Python String rfind() Method Example 3

This method takes other three parameters including two optional. Let's provide start and end index to the method.

Output:

18
6

Next TopicPython Strings





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA