如何使用unicode数据打印unicode字符的值?

2024-09-19 23:41:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在循环中打印unicode字符:

for i in range(0, 10):
    unicodedata.normalize('NFKD', '\u00a{i}')

但这导致了下一个错误:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape

然而,想要的结果是:

¡
¢
£
¤
...

你对如何实现这一点有什么想法吗


Tags: infor错误unicoderangeerror字符can
1条回答
网友
1楼 · 发布于 2024-09-19 23:41:15

只需使用^{}(“返回表示Unicode代码点为整数i的字符的字符串”)而不是字符串格式

>>> for i in range(0, 10):
...     print(chr(0xa0 + i))
...

¡
¢
£
¤
¥
¦
§
¨
©
>>>

相关问题 更多 >