Bytes indexing returns an int
Terry Reedy
tjreedy at udel.edu
Tue Jan 7 09:29:41 EST 2014
On 1/7/2014 6:13 AM, Steven D'Aprano wrote:
> Does anyone know what the rationale behind making byte-string indexing
> return an int rather than a byte-string of length one?
>
> That is, given b = b'xyz', b[1] returns 121 rather than b'y'.
This former is the normal behavior of sequences, the latter is peculiar
to strings, because there is no separate character class. A byte is a
count n, 0 <= n < 256 and bytes and bytearrays are sequences of bytes.
It was ultimately Guido's decision after some discussion and debate on,
I believe, the py3k list. I do not remember enough to be any more specific.
--
Terry Jan Reedy
More information about the Python-list
mailing list