Text is always Unicode and is represented by the str
type, and binary data is represented by the bytes
type. A string is an abstract representation of text. A string consists of characters, which are also abstract entities not tied to any particular binary representation.The encoding is a way to represent abstract characters in binary data.
下面这段话特别有意思:
Which reminds us that, in a different context, even speech itself — language — may be regarded as a form of encoding. In much of early modern philosophy (think of Hobbes and Locke) speech (or language) was basically considered to be an encoding of thoughts and ideas. Communication happens when I encode my thought into language and say something — speak to you. You hear the sound of my words and decode it back into ideas. We achieve communication when I successfully transmit a thought from my mind to your mind via language. You understand me when — as a result of my speech — you have the same idea in your mind as I have in mine.
- !Note: PEP 3120 -- Using
UTF-8
as the default source encoding. (Python3