Python String rfind() Method Syntax

Syntax:  str.rfind(sub, start, end)

Parameters: 

  • sub: It’s the substring that needs to be searched in the given string. 
  • start: Starting position where the sub needs to be checked within the string. 
  • end: Ending position where suffix needs to be checked within the string. 

Note: If start and end indexes are not provided then, by default it takes 0 and length-1 as starting and ending indexes where ending indexes are not included in our search.

Return:  Returns the right-most index of the substring if it is found in the given string; if not found, then it returns -1.

Python String rfind() Method

Python String rfind() method returns the rightmost index of the substring if found in the given string. If not found then it returns -1.

Similar Reads

Python String rfind() Method Syntax

Syntax:  str.rfind(sub, start, end) Parameters:  sub: It’s the substring that needs to be searched in the given string.  start: Starting position where the sub needs to be checked within the string.  end: Ending position where suffix needs to be checked within the string.  Note: If start and end indexes are not provided then, by default it takes 0 and length-1 as starting and ending indexes where ending indexes are not included in our search. Return:  Returns the right-most index of the substring if it is found in the given string; if not found, then it returns -1....

Python String rfind() Method Example

Python3 string = "GeeksForGeeks" print(string.rfind("Geeks"))...