在Python中返回chr(ord('A'))的值
1)Python ord() 功能
ord()function是Python中的库函数,它接受一个字符并返回其ASCII值。
示例
print(ord('A')) //返回65
2)Python chr() 功能
chr()function是Python中的一个库函数,它接受一个值(ASCII码)并返回字符。
示例
print(chr(65)) //返回A
chr(ord('A'))的返回值
语句chr(ord('A'))求值– ord('A')将返回65,然后chr(65)将返回ASCII代码65的字符值,因此将返回'A'。
Python代码演示示例 chr() 和 ord() 职能
# python代码演示示例# chr() and ord() function
# 打印ASCII码
c = 'A'
print("ASCII value of " + c + " is = ", ord(c))
c = 'X'
print("ASCII value of " + c + " is = ", ord(c))
c = 'a'
print("ASCII value of " + c + " is = ", ord(c))
c = 'z'
print("ASCII value of " + c + " is = ", ord(c))
# 打印字符
val = 65
print("CHAR value of ", val, " is = " + chr(val))
val = 88
print("CHAR value of ", val, " is = " + chr(val))
val = 97
print("CHAR value of ", val, " is = " + chr(val))
val = 122
print("CHAR value of ", val, " is = " + chr(val))
# chr(ord('A')
print("value of the statement is: " + chr(ord('A')))
输出结果
ASCII value of A is = 65ASCII value of X is = 88
ASCII value of a is = 97
ASCII value of z is = 122
CHAR value of 65 is = A
CHAR value of 88 is = X
CHAR value of 97 is = a
CHAR value of 122 is = z
value of the statement is: A
以上是 在Python中返回chr(ord('A'))的值 的全部内容, 来源链接: utcz.com/z/350119.html