Python2
>>> a = u"hello" >>> b = b"hello" >>> c = "hello" >>> type(a), type(a.encode("utf8")), type(a.decode("utf8")) (<type 'unicode'>, <type 'str'>, <type 'unicode'>) >>> type(b), type(b.encode("utf8")), type(b.decode("utf8")) (<type 'str'>, <type 'str'>, <type 'unicode'>) >>> type(c), type(c.encode("utf8")), type(c.decode("utf8")) (<type 'str'>, <type 'str'>, <type 'unicode'>) unicode.encode() => str str.decode() => unicode
Python3
>>> a = "hello" >>> b = b"hello" >>> type(a), type(a.encode("utf8")) (<class 'str'>, <class 'bytes'>) >>> type(b), type(b.decode("utf8")) (<class 'bytes'>, <class 'str'>) str.encode() => bytes bytes.decode() => str
速记
Unicode => Str => Bytes,简称USB……
Add Comment