bytes/strings in python 2 and 3

I was trying to convert some python code from 2 to 3 and found this documentation regarding string and bytes representation. Some of the examples really help make it clear are:

>>>> b''=''
False

>>>> b'xyz'[0]
120

>>>> b'xyz'[0:1]
b'x'

>>>> b'xyz'[3:4]
b''

The first show comparing byte is not the same as unicode of the same string. The second shows that indexing a byte string return an integer. The third one show how to correctly index a byte character out of a byte string by using slicing. The last one show that there is no index out of range warning if slicing outside the length of a byte string, just a empty byte string.

See bytes/unicode comparison section for more explanation.

Advertisements