Coding-Notes icon indicating copy to clipboard operation
Coding-Notes copied to clipboard

Python ASCII码与字符相互转换

Open Lucifer-ww opened this issue 5 years ago • 0 comments

:octocat:以下代码用于实现ASCII码与字符相互转换:(来自菜鸟教程)

# Filename : test.py
# author by : www.runoob.com
 
# 用户输入字符
c = input("请输入一个字符: ")
 
# 用户输入ASCII码,并将输入的数字转为整型
a = int(input("请输入一个ASCII码: "))
 
 
print( c + " 的ASCII 码为", ord(c))
print( a , " 对应的字符为", chr(a))

输入与输出

python3 test.py 
请输入一个字符: a
请输入一个ASCII码: 101
a 的ASCII 码为 97
101  对应的字符为 e

Lucifer-ww avatar May 19 '20 05:05 Lucifer-ww