Python:Ascii character<->decimal representation

2019-03-25 10:30发布

问题:

Hi I need to be able to convert a ascii character into its decimal equivalent and vice-versa.

How can I do that?

回答1:

num=ord(char)
char=chr(num)

For example,

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

You can read more about the built-in functions in Python here.



回答2:

Use ord to convert a character into an integer, and chr for vice-versa.



回答3:

ord



标签: python ascii