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''=''

>>>> b'xyz'[0]

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

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

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s