< Prev
Next >

Python - String find() Method

The find() string method determines the index of the first 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.find('ro')
index2 = s2.find('li')

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

Output is :

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

Program Analysis

Please share this article -

< Prev
Next >
< String index() Method
String rfind() 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