Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: Section 6.5 on len ignores negative indexing, might confuse readers #111

Open
sahi1l opened this issue Sep 6, 2018 · 1 comment
Assignees

Comments

@sahi1l
Copy link
Contributor

sahi1l commented Sep 6, 2018

Describe the bug
In Section 6.5, much is made about how one can find the last character of a string, saying,

Typically, a Python programmer will access the last character by combining the two lines of code from above.
lastch = fruit[len(fruit)-1]

However, in previous sections we have already seen that we can get the last character by typing fruit[-1]. A reader may be confused, wondering what is wrong with negative indexing that this section tells them that "a Python programmer" wouldn't even use it. I think the artificiality of the example should be acknowledged.

A possible non-redundant use of the len function would be to find the character in the middle of the string. e.g. if fruit="grape" then fruit[len(fruit)//2] returns "a".

@dananhd
Copy link
Collaborator

dananhd commented Oct 5, 2018

#126 pending pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants