天天看點

python 字元轉ascii_Python ASCII碼與字元互相轉換

ASCII ((American Standard Code for Information Interchange): 美國資訊交換标準代碼)是基于拉丁字母的一套電腦編碼系統,主要用于顯示現代英語和其他西歐語言。它是最通用的資訊交換标準,并等同于國際标準ISO/IEC 646。

在python中,經常要用到它和字元的互相轉換,這裡做了一個例子,僅供參考:

c = input("Please input a char: ")

a = int(input("Please input a ascii:"))

while True:

if a < 0:

print("ascii is wrong, Plese try again")

a = int(input("Please input a ascii:"))

elif a > 1000:

print("ascii is wrong, Plese try again")

a = int(input("Please input a ascii:"))

else:

break

print(" this is a ascii test")

print("assic is:",ord(c))

print(" char is:", chr(a))

參考路徑:

AS3中ASCII碼和字元互轉函數

AS3中ASCII碼和字元互轉函數 字元轉成ASCII碼: 格式:字元串變量.charCodeAt(字元位置); var str:String = “A”; trace(str.charCodeAt(