In [1]:
i = ord('A')
print(i)


65

In [2]:
print(type(i))


<class 'int'>

In [3]:
# ord('abc')
# TypeError: ord() expected a character, but string of length 3 found

In [4]:
s = hex(i)
print(s)


0x41

In [5]:
print(type(s))


<class 'str'>

In [6]:
print(format(i, '04x'))


0041

In [7]:
print(format(i, '#06x'))


0x0041

In [8]:
print(format(ord('X'), '#08x'))


0x000058

In [9]:
print(format(ord('💯'), '#08x'))


0x01f4af

In [10]:
# ord('🇯🇵')
# TypeError: ord() expected a character, but string of length 2 found

In [11]:
print(len('🇯🇵'))


2

In [12]:
print(chr(65))


A

In [13]:
print(type(chr(65)))


<class 'str'>

In [14]:
print(65 == 0x41)


True

In [15]:
print(chr(0x41))


A

In [16]:
print(chr(0x000041))


A

In [17]:
s = '0x0041'

In [18]:
print(int(s, 16))


65

In [19]:
print(chr(int(s, 16)))


A

In [20]:
s = 'U+0041'

In [21]:
print(s[2:])


0041

In [22]:
print(chr(int(s[2:], 16)))


A

In [23]:
print('\x41')


A

In [24]:
print('\u0041')


A

In [25]:
print('\U00000041')


A

In [26]:
print('\U0001f4af')


💯

In [27]:
# print('\u041')
# SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape

In [28]:
# print('\U0000041')
# SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-8: truncated \UXXXXXXXX escape

In [29]:
print('\u0041\u0042\u0043')


ABC

In [30]:
print(len('\u0041\u0042\u0043'))


3

In [31]:
print(r'\u0041\u0042\u0043')


\u0041\u0042\u0043

In [32]:
print(len(r'\u0041\u0042\u0043'))


18