gpt4 book ai didi

python - 是否有可能知道 chr 使用 Python 接受的最大数量?

转载 作者:太空狗 更新时间:2023-10-30 00:31:37 26 4
gpt4 key购买 nike

来自 chr 的 Python 文档内置函数,chr 接受的最大值是 1114111(十进制)或 0x10FFFF(16 进制)。事实上

>>> chr(1114112)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
chr(1114112)
ValueError: chr() arg not in range(0x110000)

我的第一个问题如下,为什么是这个数字?第二个问题是:如果这个数字发生变化,是否可以通过 Python 命令知道 chr 接受的最大值?

最佳答案

使用sys.maxunicode :

An integer giving the value of the largest Unicode code point, i.e. 1114111 (0x10FFFF in hexadecimal).

在我的 Python 2.7 UCS-2 构建中,unichr() 支持的最大 Unicode 字符是 0xFFFF:

>>> import sys
>>> sys.maxunicode
65535

但 Python 3.3 及更新版本切换到 Unicode 字符串的新内部存储格式,现在最大值始终 0x10FFFF。参见 PEP 393 .

0x10FFFF 是 Unicode 标准中定义的最大 Unicode 代码点。引用 Wikipedia article on Unicode :

Unicode defines a codespace of 1,114,112 code points in the range 0 to 10FFFF.

关于python - 是否有可能知道 chr 使用 Python 接受的最大数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34813535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com