fopp icon indicating copy to clipboard operation
fopp copied to clipboard

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

Open sahi1l opened this issue 6 years ago • 1 comments

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".

sahi1l avatar Sep 06 '18 02:09 sahi1l

#126 pending pull request

dananhd avatar Oct 05 '18 16:10 dananhd