showkey
showkey

Reputation: 290

how to get the unicode format of "你"?

I knew that the unicode of (meaning you) is \x4F\x60. How can i get it from my python command console?

>>> print("你")
你
>>> print(("你").encode("gbk"))
b'\xc4\xe3'
>>> print(("你").encode("utf-8"))
b'\xe4\xbd\xa0

I am in python3.3 .

Upvotes: 0

Views: 98

Answers (2)

metatoaster
metatoaster

Reputation: 18908

If you want the actual unicode codepoint of any given character in Python 3, you can simply use ord to get the raw number

>>> ord('你')
20320

However, you really should search around and you might find answers in other SO articles like

Also read up on what Unicode actually is, which was also linked there.

Upvotes: 3

RemcoGerlich
RemcoGerlich

Reputation: 31260

I think you are looking for

>>> print(("你").encode("unicode-escape"))
b"\\u4f60"

Which shows that 你 is \u4F60. I don't know a specific encoding that turns that into the two bytes 4F and 60.

(I only tested this on 2.7.3, assuming that "unicode-escape" also exists in Python 3)

Upvotes: 2

Related Questions