python - python 中的 32 位 unicode

标签 python unicode

Python 有一个转义序列 \u 来显示 unicode 值。但是,这仅限于 16 位 unicode 值。那就是

>>> '\u1020'
'ဠ'

而 32 位解码值不起作用。也就是

>>> '\u00001000'
'\x001000'

这显然是错误的。 python documentation提及

The escape sequence \u0020 indicates to insert the Unicode character with the ordinal value 0x0020 (the space character) at the given position.

最佳答案

python How To Unicode明确提到使用 '\U' 来表示 32 位 unicode 序列。

>>> "\u0394"                          # Using a 16-bit hex value
'Δ'
>>> "\U00000394"                      # Using a 32-bit hex value
'Δ'

在这种情况下

>>> '\U00001000'
'က'

关于python - python 中的 32 位 unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27702983/

相关文章:

html - 大表情符号在 Chrome 和移动浏览器上被截断

python - PyCharm 可以找到模块但执行返回 ModuleNotFound 错误

python - 如何在 pandas 的 fillna 中使用 math.sin()

linux - 为 Linux 构建的 NSIS unicode

C: sscanf 问题

jquery - 如何转义 JSON 字符串中的 unicode 语法 (u'foo')?

Python 正则表达式匹配非 ascii 名称

使用 Supervisor 进行 Python 日志记录

python - 在 Python 中启用和禁用调试消息

python - 获取 Python 中特殊字符前后的字符串