如果字符串在 Python 3 中是 unicode,为什么需要 unicode 文字?

Why unicode literal is needed if string is unicode in Python 3?

根据我的理解,Python3 中的字符串是 UTF-8,因此我们应该能够使用除私有区域之外的任何 unicode 代码点。那为什么还需要 Unicode literalu"..."

下面的 PEP 414 但不确定是什么意思。

Python 2 supports a concept of "raw" Unicode literals that don't meet the conventional definition of a raw string: \uXXXX and \UXXXXXXXX escape sequences are still processed by the compiler and converted to the appropriate Unicode code points when creating the associated Unicode objects.

Python 3 has no corresponding concept - the compiler performs no preprocessing of the contents of raw string literals. This matches the behaviour of 8-bit raw string literals in Python 2.

它在 Python 3 中是多余的,但为了促进对 Python 2 的部分可移植性(例如,对于使用 six 或类似助手编写的交叉兼容脚本,它是允许的).