Bytes indexing returns an int

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jan 7 07:04:25 EST 2014


Ervin Hegedüs wrote:

> hi,
> 
> On Tue, Jan 07, 2014 at 10:13:29PM +1100, 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 is especially surprising when one considers that it's easy to
>> extract the ordinal value of a byte:
>> 
>> ord(b'y') => 121
> 
> Which Python version?

My apologies... I've been so taken up with various threads on this list
discussing Python 3, I forgot to mention that I'm talking about Python 3.

I understand the behaviour of bytes and bytearray, I'm asking *why* that
specific behaviour was chosen.



-- 
Steven




More information about the Python-list mailing list