Use Python string rfind method to find a sub string from right

Find a substring from right

We can search a sub from the end of a string back to the start by using rfind method. rfind method has the following syntax.

s.rfind(sub, [, start [, end]])

Like find, but scans from the end (right to left).


searchStr =  "Red Blue Violet Green Blue Yellow Black"
print searchStr.rfind("Blue")

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary