Slicing and offsets

Sheila King sheila at spamcop.net
Thu Jan 18 13:24:59 EST 2001


On Thu, 18 Jan 2001 17:53:30 GMT, Darren New <dnew at san.rr.com> wrote in
comp.lang.python in article <3A672D9B.6E71F709 at san.rr.com>:

:gustabares at my-deja.com wrote:
:> Why is it that when I slice S it's no longer the 0 offset anymore, but
:> now it is 1?
:
:I'm not sure I understand the question, but I'm guessing this might be the
:answer:
:
:You don't "slice S". Instead, you're asking for a slice of S. Unlike pie,
:this doesn't change S. Slicing is a function that gives back a new and
:different string that's independent of what you sliced.

Ah, I think you have got it. I've been following this thread, trying to see
what it was about.

Maybe this illustration would help?

>>> S='spam'
>>> S[0:]
'spam'
>>> S[1:]
'pam'
>>> T=S[1:]
>>> T[0:]
'pam'
>>> 



--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



More information about the Python-list mailing list