Skip to content

Incorrect index() section uses find() #943

Description

@myselfanandvp

Description

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 substring
challenge = 'thirty days of python'
print(challenge.find('y'))  # 5
print(challenge.find('th'))  # 0


Why this is a problem

The section is labeled index(), but both examples use find():

challenge.find('y')
challenge.find('th')

This can be confusing for learners because find() and index() have similar behavior, but they are different string methods.

For example, when the substring is not found:

'hello'.find('x')    # -1
'hello'.index('x')   # ValueError

Suggested change

Replace the find() calls with index() calls:

# index(): Returns the index of substring
challenge = 'thirty days of python'
print(challenge.index('y'))  # 5
print(challenge.index('th'))  # 0

The existing find() section earlier in the file can remain unchanged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions