The rindex() method in Python String returns the last or highest index where the substring inside the string in case substring is found, else it raises an exception when no such index exists, and this optionally restricts the search to a specific string[beg:end].
Here is the syntax for rindex() method:
str.rindex(str, beg=0 end=len(string))
This method is responsible to return the last index when found otherwise it raises an exception when str is not found.
The following example shows the usage of rindex() method.
#!/usr/bin/python str1 = "this is string example....wow!!!"; str2 = "is"; print str1.rindex(str2) print str1.index(str2)
When the above program is run, it produces following result:
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.