< Prev
Next >

Python - String orfind() method

The rfind() string method determines the index of the last occurrence of a particular string value within the invoked string object.

The rfind() method perform a case-sensitive search, when it comes to search an index of a specific value in a string object.

# Python - Program to find a particular value in a String.

s1 = 'Rock and roll!'
s2 = 'Live a happy life!'

index1 = s1.rfind('ro')
index2 = s2.rfind('li')

print('last index of ro in ', s1, ' : ', index1)
print('last index of li in ', s1, ' : ', index2)

Output is :

last index of ro in  Rock and roll!  :  9
last index of li in  Rock and roll!  :  13

Program Analysis

Please share this article -

< Prev
Next >
< String find() method
String rindex() method >


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition