← Go Back

How to Get ASCII Code of a Character and Vice Versa

The ord() built-in function lets you obtain the ordinal number that is associated with the specified character. Note that "ASCII code" is used in a comprehensive sense, since it does include unicode characters.

>>> ord("a")
97

To recover a character from its ordinal, chr() is used.

>>> chr(97)
'a'


characters ascii