Menu Close

Python String rfind() Method

Python string rfind

In this tutorial, you will learn about the Python string rfind() method along with examples. rfind function in Python returns the highest index of the matching string.

In the previous tutorial, we have seen the Python string rsplit() method to split the string from the right of the string.

Python string rfind() method

Python rfind() string method finds a substring in the string and returns the highest index of that string.
Python string rfind() returns -1 if substring not found.
Python rfind method is almost the same as Python string rindex() method.


The syntax of the rfind function in Python is:-

string.rfind(sub, start, end)


The rfind() function in python accept three parameters: sub, strat and end.

  • sub:- substring to be searched.
  • start:- starting index to start searching.
  • end:- end index to stop searching.

Return Value

The Python python string rfind() return either highest index of substring or -1.

Python string rfind() Example

Here we will write some Python code to understand rfind() method.

Example 1:

a = 'Python is Programming Language'
result = a.rfind('e')

Output will be:- 29

Example 2:

a = 'Programming Funda'
result = a.rfind('n')

Output will be:- 14

Example 3:

a = 'Programming Funda'
result = a.rfind('is')

In the above example output will be -1 because the specified substring not included in string a.


In this tutorial, you have learned the Python string rfind method to search substring from the string and return the highest index of the substring. if the substring not found, it will return -1.

Python string rfind() almost the same as string rindex() method. I hope this tutorial will help you. if you like this article, please share it with your friends who want to learn Python programming.

Other string methods

For More Information:- Click Here

Python string rsplit() method
Python String ljust() Method

Related Posts