Copyright © tutorialspoint.com

Python String rindex() Method

previous next


Description:

This method returns the last index where the substring str is found, or raises an exception if no such index exists, optionally restricting the search to string[beg:end].

Syntax:

str.rindex(str, beg=0 end=len(string))

Parameters:

Here is the detail of parameters:

Return Value:

It returns last index if found otherwise raises an exception if str is not found.

Example:

#!/usr/bin/python

str = "this is string example....wow!!!";
str = "is";

print str.rindex(str);
print str.index(str);

This will produce following result:

5
2

previous next

Copyright © tutorialspoint.com