A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 one year ago
Regarding strings in Python, we know some_string[0] is the index of the first character of string some_string. Why is some_string[1] the index of the last character instead of some_string[0]? Would python evaluate 0 to 0 anyway?
anonymous
 one year ago
Regarding strings in Python, we know some_string[0] is the index of the first character of string some_string. Why is some_string[1] the index of the last character instead of some_string[0]? Would python evaluate 0 to 0 anyway?

This Question is Open

Curry
 one year ago
Best ResponseYou've already chosen the best response.0Intuitively, 0 is the first element in the string. So 1 is the one before it, or in other words, the last element, cause it's wrapping. In other words, the negative sign doesn't signify subtraction. it just signifies the value of the number inside the brackets. so 0 = 0 and 1 = 1 and 1=1.

Curry
 one year ago
Best ResponseYou've already chosen the best response.0I think you got confused cause you thought the 0 minus one less than 0. but it doesn't, hope that helps.

Curry
 one year ago
Best ResponseYou've already chosen the best response.0to do that, i believe you'd use the actual subtract operator, like . not just one . Make sense?

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0\(\color{blue}{\text{Originally Posted by}}\) @ratinthecat Would python evaluate 0 to 0 anyway? \(\color{blue}{\text{End of Quote}}\) This is one reason, but there is another reason though. Here is one way to think of python indexing for negative values: `some_string[i] == some_string[len(some_string) + i]` Since the `len(...)  1` gives the last index, the `1` gives the last element.

anonymous
 one year ago
Best ResponseYou've already chosen the best response.0These explanations really help. Thanks Wio and Curry!
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.