Matt Matt - 4 months ago 33
Python Question

ASCII value of a character in Python

How do I get the ASCII value of a character as an int in Python?


From here:

function ord() would get 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)

There is also the unichr function, returning the Unicode character whose ordinal is the unichr argument:

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