Python – Get the Unicode code of any character

In this post we’ll be creating a Python script that will retrieve the Unicode code of a character as an integer.

To achieve this we use the ‘ord()’ function, see the example below for how this is done.

print(ord('a'))
#Returns 97

print(ord('b'))
#Returns 98

Similarly we can inverse this and convert a Unicode code back in to a character. To do this we would use the ‘chr()’ function as seen below.

print(chr(97))
#Returns a

print(chr(98))
#Returns b

Leave a Reply