Incorrect index() section uses find()

Open Beginner friendly
#943 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
92/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
documentation

Research direction

Open 04_Day_Strings/day_4.py and locate the index() section. Compare it with the surrounding find() section, then change the two calls in the index() examples so they demonstrate index() and retain the shown outputs. Done means the section is labeled index() and no longer uses find(), while the earlier find() section remains unchanged.

Written by the indexing model from the issue text.

Description

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.
Dominant language
Python
Stars
74.2k
Forks
13.5k
Avg merge
5d 5h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Asabeneh/30-Days-Of-Python

All issues in Asabeneh/30-Days-Of-Python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.