How to interpret the result of the format (n, 'c') outside of ASCII?

Consider the following example:

format(97, 'c')
format(6211, 'c')

The first exits 'a', which are obviously correct; however the second conclusion 'C', which I do not understand why.

The format specification indicates that:

'c': Symbol. Converts an integer to the corresponding Unicode character before printing.

So you should not 6211match your Unicode character, which is in Chinese?

Associated sysinfo: CPython 2.7.10, on Fedora 22.

+4
source share
1 answer

You see Problem 7267 - format method: c presentation type broken in 2.7 .

, format(int, 'c') int.__format__('c'), str ( Python 2.x), (0, 256). , , 256, 0. -

>>> format(256,'c')
'\x00'

, , Python 3, unicode, , , Python 3.x.

, , unichr() -

>>> unichr(0x6211)
u'\u6211'
>>> print(unichr(0x6211))

, , : 6211 - , , , 0x1843. , , 0x6211, , , format(0x6211,'c') Python 3.x.

+6
source

Source: https://habr.com/ru/post/1609565/


All Articles