Numeric type conversions

Lie Lie.1296 at
Wed Jun 18 20:20:47 CEST 2008

On Jun 18, 12:23 am, John Dann <n... at> wrote:
> On Tue, 17 Jun 2008 08:58:11 -0700 (PDT), MRAB
> <goo... at> wrote:
> >[snip]
> >Please note that in slicing the start position is included and the end
> >position is excluded, so that should be ByteStream[12:14].
> Yes, I just tripped over that, in fact, hence the error in my original
> post. I suppose there must be some logic in including the start
> position but excluding the end position, though it does escape me for
> now. I can understand making a range inclusive or exclusive but not a
> mixture of the two. Suppose it's just something you have to get used
> to with Python and, no doubt, much commented on in the past.

There is actually a logic to that. It's explained in the help/tutorial
file, that you should think about the index as a cursor, the index
itself doesn't point to the item itself, but to the interval between
the item.

(read this on a monospace font, or it'll look screwed up)
0   1   2   3   4   5
| A | B | C | D | E |
-5  -4  -3  -2  -1  0

So to get BCD, you say [1:4]

More information about the Python-list mailing list