Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

index in string with range

  • index
text = "The black cat climbed the green tree."
print(text.index("c"))      # 7
print(text.index("c", 8))   # 10

print(text.index("gr", 8))      # 26
print(text.index("gr", 8, 16))
7
10
26
Traceback (most recent call last):
  File "examples/strings/index2.py", line 8, in <module>
    print a.index("gr", 8, 16) 
ValueError: substring not found