In [1]:
i = ord('A')
print(i)
In [2]:
print(type(i))
In [3]:
# ord('abc')
# TypeError: ord() expected a character, but string of length 3 found
In [4]:
s = hex(i)
print(s)
In [5]:
print(type(s))
In [6]:
print(format(i, '04x'))
In [7]:
print(format(i, '#06x'))
In [8]:
print(format(ord('X'), '#08x'))
In [9]:
print(format(ord('💯'), '#08x'))
In [10]:
# ord('🇯🇵')
# TypeError: ord() expected a character, but string of length 2 found
In [11]:
print(len('🇯🇵'))
In [12]:
print(chr(65))
In [13]:
print(type(chr(65)))
In [14]:
print(65 == 0x41)
In [15]:
print(chr(0x41))
In [16]:
print(chr(0x000041))
In [17]:
s = '0x0041'
In [18]:
print(int(s, 16))
In [19]:
print(chr(int(s, 16)))
In [20]:
s = 'U+0041'
In [21]:
print(s[2:])
In [22]:
print(chr(int(s[2:], 16)))
In [23]:
print('\x41')
In [24]:
print('\u0041')
In [25]:
print('\U00000041')
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')
In [30]:
print(len('\u0041\u0042\u0043'))
In [31]:
print(r'\u0041\u0042\u0043')
In [32]:
print(len(r'\u0041\u0042\u0043'))