How can I convert a character to a integer in Python, and viceversa?

The Question :

345 people think this question is useful

I want to get, given a character, its ASCII value.

For example, for the character a, I want to get 97, and vice versa.

The Question Comments :

The Answer 1

577 people think this answer is useful

Use chr() and ord():

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

The Answer 2

68 people think this answer is useful
>>> ord('a')
97
>>> chr(97)
'a'

The Answer 3

16 people think this answer is useful

ord and chr

Add a Comment