[Tutor] How can I get ASCII of 'a' and '1'?

Kent Johnson kent37 at tds.net
Sat Oct 6 15:00:04 CEST 2007

林培恒 wrote:
>     How can I get ASCII for alphabet and number, such as 'a' and '1'. I can get ASCII for character naturally in C but I don't how to in Python.

You can get the character codes using ord():
In [1]: ord('a')
Out[1]: 97
In [2]: ord('1')
Out[2]: 49

The inverse function is chr():
In [3]: chr(97)
Out[3]: 'a'


More information about the Tutor mailing list