Python ASCII碼與字符相互轉換


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

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

 1 c = input("Please input a char: ")
 2 a = int(input("Please input a ascii:"))
 3 while True:
 4     if a < 0:
 5         print("ascii is wrong, Plese try again")
 6         a = int(input("Please input a ascii:"))
 7     elif a > 1000:
 8         print("ascii is wrong, Plese try again")
 9         a = int(input("Please input a ascii:"))
10     else:
11         break
12 
13 print(" this is a ascii test")
14 print("assic is:",ord(c))
15 print(" char is:", chr(a))

  參考路徑:

https://www.runoob.com/python3/python3-ascii-character.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM