Advertisement



< Prev
Next >



Python - String index() Method




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





Both forms of index() 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.


s1 = 'Let us Jazz and jam'
s2 = 'Live and let live'

index1 = s1.index('j')
index2 = s2.index('live')

print('First index of J in ', s1, ' : ', index1)
print('First index of live in ', s1, ' : ', index2)


Output is :


First index of J in  Let us Jazz and jam  :  7
First index of live in  Let us Jazz and jam  :  13


Program Analysis






Please share this article -




< Prev
Next >
< String endswith() Method
String find() 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


Advertisement