我有一个Python程序,它存储一个包含Unicode数字字符串的字典,然后获取该字符串并打印出实际的字符。 我的代码如下所示:
unicodeChars = {'bullet': 'u+2022'}
print(chr(unicodeChars['bullet']))
但是当我运行程序时,它打印出 Unicode 字符串(
u+2202
),而不是实际的字符。我该如何让我的程序做到这一点?
我在 Windows 11 64 位笔记本电脑中使用 Python 3。
查看Unicode HOWTO。你会发现你确实在寻找这个:
unicode_chars = {'bullet': '\u2022'}
print(unicode_chars['bullet'])
答案是
chr(int(unicodeChars['bullet'][2:]))
。
谢谢@sahasrara62 的回答!