Slicing and offsets
Alex Martelli
aleaxit at yahoo.com
Thu Jan 18 04:47:08 EST 2001
<gustabares at my-deja.com> wrote in message
news:945bvp$thj$1 at nnrp1.deja.com...
> I got a newbie question here...
>
> >>> S = "spam"
> >>> S[0]
> 's'
S[0] -> the first item in sequence S.
> >>> S[1:]
> 'pam'
S[1:] -> all items in sequence S *except* the first one.
> >>>
>
> Why is it that when I slice S it's no longer the 0 offset anymore, but
> now it is 1?
Sorry, I don't understand that question. Whether you're indexing
or slicing, the first element is at index 0; if you index at 1, or
slice from 1, you won't get the first element.
> >>> S[0:]
> 'spam'
if you do index at 0, or slice from 0, you WILL get the first
element (and, if a slice, possibly more elements afterwards).
> Thanks for any help and sorry for the simple question:)
Anything BUT simple -- I don't understand what the question IS!
Alex
More information about the Python-list
mailing list