Posts

Showing posts with the label string methods

.find() and .index() string methods in Python

 The difference between these two methods is that .index()  method raises error while the other does not. str1 = "My name is Abdur." print(str1.find("is")) # gives index of first character occurence print(str1.find("iss")) #does not raises error, returns -1 print(str1.index("is")) # gives index of first character occurence print(str1.index("iss")) # raises error