chr()函数以及Python中的示例
Pythonchr()功能
chr()function是Python中的一个库函数,用于从给定的ASCII码(整数值)中获取字符值,它接受一个数字(应为ASCII码)并返回字符。
语法:
chr(number)
参数:number–我们想要其字符值的ASCII码(整数值)。
返回值:str–返回字符(字符串)值。
示例
Input:
num = 65
print(chr(num))
Output:
APython代码从给定的ASCII代码中查找字符值
#python代码演示一个例子
# of chr() function
#数字(A的ASCII码)
num = 65
print("character value of ", num, " is = ", chr(num))
num = 120
print("character value of ", num, " is = ", chr(num))
num = 190
print("character value of ", num, " is = ", chr(num))输出结果
character value of 65 is = A character value of 120 is = x character value of 190 is = ¾