368
votes

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

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

4

4 Answers

616
votes

Use chr() and ord():

>>> chr(97)
'a'
>>> ord('a')
97
86
votes
>>> ord('a')
97
>>> chr(97)
'a'
18
votes

ord and chr

0
votes

For long string you could use this.

 ''.join(map(str, map(ord, 'pantente')))