Searching the pattern in a String using find and index

try:
    s="brown box red pencil brown pen red pen red box"
    print s.find("red")
    print s.find("red",13,len(s))
    print s.find("red",34,len(s))
    print s.find("crow")
    print s.index("red")
    print s.index("red",13,len(s))
    print s.index("red",34,len(s))
    print s.index("crow")
except ValueError:
   print "crow not a pattern in string"
   

No comments: