From my perspective, this is the most important change of all:
Unicode
Python 2 has ASCII
Now, in Python 3, we finally have Unicode (utf-8)
str() types, separate unicode(), but no byte type. Now, in Python 3, we finally have Unicode (utf-8)
strings, and 2 byte classes: byte and bytearrays.Python 2
In [2]: print 'Python', python_version()
In [3]: print type(unicode('this is like a python3 str type'))
In [4]: print type(b'byte type does not exist')
In [5]: print 'they are really' + b' the same'
In [7]: print type(bytearray(b'bytearray oddly does exist though'))
Python 3
In [6]:
print('Python', python_version())
print('strings are now utf-8 \u03BCnico\u0394é!')
In [8]:
print('Python', python_version(), end="")
print(' has', type(b' bytes for storing data'))
In [11]:
print('and Python', python_version(), end="")
print(' also has', type(bytearray(b'bytearrays')))
In [13]:
'note that we cannot add a string' + b'bytes for data'
No comments:
Post a Comment