FROM http://stackoverflow.com/questions/10060411/byte-string-vs-unicode-string-python:
A character in a str
represents one unicode character. However to represent more than 256 characters, individual unicode encodings use more than one byte per character to represent many characters. bytearray
objects give you access to the underlaying bytes. str
objects have the encode
method that takes a string representing an encoding and returns the bytearray
object that represents the string in that encoding. bytearray
objects have the decode
method that takes a string representing an encoding and returns the str
that results from interpreting the bytearray
as a string encoded in the the given encoding. Here's an example.
>>> a = "αά".encode('utf-8')
>>> a
b'\xce\xb1\xce\xac'
>>> a.decode('utf-8')
'αά'
We can see that UTF-8 is using four bytes, \xce, \xb1, \xce, and \xac to represent two characters. After the Spolsky article that Ignacio Vazquez-Abrams referred to, I would read the Python Unicode Howto.
以及干货:http://blog.csdn.net/chuanchuan608/article/details/17915959