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

Python String rindex() Method

Python String rindex() Method

Python String rindex() Method in python works almost the same as the rfind() method. It returns the last index of the specified value where the substring str is found, or raises an exception if the value is not found.

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

Parameter Values

Parameter Description
value It is Required the substring to be searched
start It is Optional. Where the index to start searching. Its default value is 0.
end It is Optional. Where to stop the search.
Here is an example of Python String rindex() Method:

xt = "Hi, How are you."
z = txt.rindex("are")
print(z)

Output:
8
Example 2:

rind = "Hello, welcome to phptpoint."
print(rind.rfind("q"))
print(rind.rindex("q"))

Output:
ValueError: substring not found

No Sidebar ads