Copyright © tutorialspoint.com

Python String rfind() Method

previous next


Description:

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

Syntax:

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

Parameters:

Here is the detail of parameters:

Return Value:

It returns last index if found and -1 otherwise.

Example:

#!/usr/bin/python

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

print str.rfind(str);
print str.rfind(str, 0, 10);
print str.rfind(str, 10, 0);

print str.find(str);
print str.find(str, 0, 10);
print str.find(str, 10, 0);

This will produce following result:

5
5
-1
2
2
-1

previous next

Copyright © tutorialspoint.com