Python:Ascii character<->decimal representation conversion

后端 未结 4 513
情歌与酒
情歌与酒 2021-02-04 04:13

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

How can I do that?

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 04:47

    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.

提交回复
热议问题