Converting Unicode in Python 3: from Character Code to Decimal

Given the Control Code column in the Wikipedia List of Unicode Characters:

 

Example 1: The Cent character

Code Glyph Decimal Description
U+0041 A 65 Latin Capital letter A

> Python Prompt:

> code = ‘0041’
>>> decimal = int(code,16)
>>> decimal
65
>>> chr(decimal)
‘A’

Example 2: The Cent character

Code Glyph Decimal Html Description
U+00A2 ¢ 0162 ¢ Cent sign          

> Python Prompt:

> code = ’00A2′
>>> decimal = int(code,16)
>>> decimal
162
>>> chr(decimal)
‘¢’

Example 3: The Greek Sigma character

Code Glyph Decimal Description
03A3 Σ 931 Greek Capital Letter Sigma

> Python Prompt

> code = ’03A3′
>>> decimal = int(code,16)
>>> decimal
931
>>> chr(decimal)
‘Σ’

Example 4: Soccer Ball

0 1 2 3 4 5 6 7 8 9 A B C D E F
U+26Bx

> Python Prompt:

> code = ’26BD’
>>> decimal = int(code,16)
>>> decimal
9917
>>> chr(decimal)
‘⚽’

Note: The Soccer ball did not display correctly in my Windows Shell, but rendered properly when I copied it into a Chrome WordPress textarea.

 

Example 5: Emoticons

1F60E 😎 smiling face with sunglasses

>>> code = ‘1F60E’
>>> decimal = int(code,16)
>>> decimal
128526
>>> chr(decimal)
‘😎’