(May-30-2017, 07:26 PM)j.crater Wrote: How did you know/decide to use decode('utf-8'), and not 'ascii' for example?Python 3 represents strings as Unicode,and will not take in data without encoding(will be bytes string if try).
If have bytes,we can decode them to a Unicode string using UTF-8.
>>> b = b'hello' >>> type(b) <class 'bytes'> >>> c = b.decode('utf-8') # Just b.decode() will do the same >>> c 'hello' >>> type(c) <class 'str'>Unicode was one biggest changes moving from Python 2 to Python 3.
Python 3 has UTF-8 as default encoding,Python 2 had ASCII as default encoding.