输入Unicode字符串,输出对应的字符

问题描述 投票:0回答:2

我有一个Python程序,它存储一个包含Unicode数字字符串的字典,然后获取该字符串并打印出实际的字符。 我的代码如下所示:

unicodeChars = {'bullet': 'u+2022'}
print(chr(unicodeChars['bullet']))

但是当我运行程序时,它打印出 Unicode 字符串(

u+2202
),而不是实际的字符。我该如何让我的程序做到这一点?

我在 Windows 11 64 位笔记本电脑中使用 Python 3。

python python-3.x python-unicode
2个回答
2
投票

查看Unicode HOWTO。你会发现你确实在寻找这个:

unicode_chars = {'bullet': '\u2022'}
print(unicode_chars['bullet'])

-1
投票

答案是

chr(int(unicodeChars['bullet'][2:]))
。 谢谢@sahasrara62 的回答!

© www.soinside.com 2019 - 2024. All rights reserved.