You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The index() section in 04_Day_Strings/day_4.py incorrectly demonstrates the find() method instead of the index() method.
Current content
# index(): Returns the index of substringchallenge='thirty days of python'print(challenge.find('y')) # 5print(challenge.find('th')) # 0WhythisisaproblemThesectionislabeledindex(), butbothexamplesusefind():
challenge.find('y')
challenge.find('th')
Thiscanbeconfusingforlearnersbecausefind() andindex() havesimilarbehavior, buttheyaredifferentstringmethods.
Forexample, whenthesubstringisnotfound:
'hello'.find('x') # -1'hello'.index('x') # ValueErrorSuggestedchangeReplacethefind() callswithindex() calls:
# index(): Returns the index of substringchallenge='thirty days of python'print(challenge.index('y')) # 5print(challenge.index('th')) # 0Theexistingfind() sectionearlierinthefilecanremainunchanged.
Activity