[Python-3000] about bytes

Georg Brandl g.brandl at gmx.net
Thu Jun 26 22:23:38 CEST 2008


nirinA raseliarison schrieb:
> why the following behavior:
> 
>     >>> b=b'thisisbytes'
>     >>> b[0] == b't'
>     False
>     >>> b[0]
>     116
> 
> i expected same thing as:
> 
>     >>> b.startswith(b't')
>     True
>     >>> b[0:1] == b't'
>     True
>     >>> b[0:1]
>     b't'
>     >>> b[:1]
>     b't'
> 
> and this is a bit curious:
> 
>     >>> b[2:5]
>     b'isi'
>     >>> for i in b[2:5]:
>         print(i)
> 
>     105
>     115
>     105

Yes. Bytes objects are sequences of bytes, which are integers.
So, in short, this is the way they work.

Georg



More information about the Python-3000 mailing list