chr()
是 Python 内置函数之一,用于将整数转换为对应的 Unicode 字符。
语法如下:
chr(i)
其中i
为整数,表示 Unicode 编码对应的码位。
以下是一些chr()
函数的使用示例:
print(chr(97)) # 输出:a
print(chr(8364)) # 输出:€
print(chr(128149)) # 输出一个心形符号
在 Python 3 中,字符串是使用 Unicode 编码的,因此chr()
函数返回的是 Unicode 字符。
chr()
是ord()
函数的逆函数。
参考: