How to get the ASCII value of a character

From here:

The function ord() gets the int value
of the char. And in case you want to
convert back after playing with the
number, function chr() does the trick.

>>> ord('a')
>>> chr(97)
>>> chr(ord('a') + 3)

In Python 2, there was also the unichr function, returning the Unicode character whose ordinal is the unichr argument:

>>> unichr(97)
>>> unichr(1234)

In Python 3 you can use chr instead of unichr.

ord() – Python 3.6.5rc1 documentation

ord() – Python 2.7.14 documentation

Leave a Comment