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
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".
The text was updated successfully, but these errors were encountered:
Describe the bug
In Section 6.5, much is made about how one can find the last character of a string, saying,
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"
thenfruit[len(fruit)//2]
returns "a".The text was updated successfully, but these errors were encountered: