1. 程式人生 > >ASCII碼與字元互轉,python

ASCII碼與字元互轉,python

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'