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.
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
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.
I share your pain: I really want things to actually make sense rather than just knowing how to make stuff work.
Join our real-time social learning platform and learn together with your friends!