简体   繁体   中英

How to print the value of unicode character with unicodedata?

I am trying to print unicode characteres in loop:

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

But this caused the next error:

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

However the wanted result is:

¡
¢
£
¤
...

Do you have some ideas how to implement this?

Just use chr(i) ("Return the string representing a character whose Unicode code point is the integer i .") instead of string-formatting things.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM