ASCII码与字符互转,python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiaotao_1/article/details/80918160

ord():字符转成ASCII码,参数为字符。
chr():ASCII码转成字符,参数为数字(0-127)

>>> help(ord)    # ord的帮助文档
Help on built-in function ord in module builtins:
ord(c, /)
    Return the Unicode code point for a one-character string.

>>> help(chr)    # chr的帮助文档
Help on built-in function chr in module builtins:
chr(i, /)
    Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff.

>>> ord('a')    # 例子
97
>>> chr(97)
'a'

猜你喜欢

转载自blog.csdn.net/xiaotao_1/article/details/80918160