.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

    

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes