Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

algotruneman

  • 2 years ago

I'm trying to get a handle on string slicing. Thanks for any help. I thought -1 referenced the last character of a string. See my Gist for the code snip. https://gist.github.com/4328274 Further reading shows that print group[start: ] is the right format. The question still remains in my mind, though.

  • This Question is Closed
  1. exchaoordo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I can't give you the deep theory, but if you try this, you'll see what's going on: x = "012345" print x[:-1] ##up to but not including last character print x[-1]##print last character print x[0:] ##up to and including last character

  2. algotruneman
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks, exchaoordo. I guess my problem is that the logic of -1 being both a reference to the last character of the string AND the penultimate (last - 1) character is confusing. But, I'll live with it and move on.

  3. exchaoordo
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    I share your pain: I really want things to actually make sense rather than just knowing how to make stuff work.

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.