在 Python 3.x 中,字符串由 Unicode 序数项组成。 (请参阅下面语言引用中的引文。)Unicode 字符串的内部表示是什么?是 UTF-16 吗?
The items of a string object are Unicode code units. A Unicode code unit is represented by a string object of one item and can hold either a 16-bit or 32-bit value representing a Unicode ordinal (the maximum value for the ordinal is given in sys.maxunicode, and depends on how Python is configured at compile time). Surrogate pairs may be present in the Unicode object, and will be reported as two separate items.
最佳答案
内部表示将在 Python 3.3 中改变,它实现了 PEP 393 .新的表示会选择ascii, latin-1, utf-8, utf-16, utf-32中的一个或几个,一般都是为了得到一个紧凑的表示。
只有在与旧版 API 对话时才会隐式转换为代理对(这些 API 仅存在于 windows 上,其中 wchar_t 是两个字节); Python 字符串将被保留。这里是release notes .
关于python - Python 3.x 中字符串的内部表示是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1838170/