Advertisement



< Prev
Next >



Python - String rindex() Method




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





Both forms of rindex() method perform a case-sensitive search, whether it comes to the search of an index of a value in a string object.

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



# Creating the string
s1 = 'Do what you Love, love what you do'

# Searching for the value 'love'  in the string
index1 = s1.rindex('love')


# Searching for the value 'do' in the string
index2 = s1.rindex('do')


print('last index of love in ', s1, ' : ', index1)
print('last index of do in ', s1, ' : ', index2)


Output is :


last index of love in  Do what you Love, love what you do  :  18
last index of do in  Do what you Love, love what you do  :  32


Program Analysis






Please share this article -




< Prev
Next >
< String rfind() Method
String center() Method >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement