Home >>Python String Methods >Python String rfind() Method

Python String rfind() Method

Python String rfind() Method

Python string rfind() method is used to find the last occurrence of the specified value. It will return -1 if the specified value is not found in the given string. It is almost the same as the rindex() method.

Syntax:
string.rfind(value, start, end)

Parameter Values

Parameter Description
value This is a required parameter. It defines the value to search for.
start This is an optional parameter. It defines where to start the search.
end This is an optional parameter. It defines where to end the search.
Here is an example of Python rfind() method:

txt = "Hi everyone. I'm Jerry."
x = txt.rfind("Jerry")
print(x)

Output:
17
Example 2:

txt = "Hi everyone. I'm Jerry."
x = txt.rfind("Jerry", 5, 15)
print(x)

Output:
-1