Python String rfind() Method

Last Updated : 31 Dec 2025

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.

Syntax of Python rfind(str,beg=0,end=len(str))

It has the following syntax:

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.

Different Examples for Python String rfind() Function

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

Example 1

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

Output:

16

Example 2

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

Output:

18

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