在Python中返回chr(ord('A'))的值

1)Python ord()函数 (1) Python ord() function)

ord() function is a library function in Python, it accepts a character and returns it's ASCII value.

ord()函数是Python中的一个库函数,它接受一个字符并返回其ASCII值。

Example:

例:

    print(ord('A')) //returns 65

2)Python chr()函数 (2) Python chr() function)

chr() function is a library function in Python, it accepts a value (ASCII code) and returns characters.

chr()函数是Python中的一个库函数,它接受一个值(ASCII码)并返回字符。

Example:

例:

    print(chr(65)) //returns A

Return value of chr(ord('A'))

chr(ord('A'))的返回值

Statement chr(ord('A')) evaluation – ord('A') will return 65 and then chr(65) will return character value of ASCII code 65, thus, it will return 'A'.

语句chr(ord('A'))评估– ord('A')将返回65 ,然后chr(65)将返回ASCII代码65的字符值,因此将返回'A'

Python code to demonstrate example of chr() and ord() functions

Python代码演示chr()和ord()函数的示例

# python code to demonstrate example of 
# chr() and ord() function

# printing ASCII codes
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))

# printing characters
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')))

Output

输出量

ASCII value of A is =  65
ASCII 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


翻译自: https://www.includehelp.com/python/return-value-of-chr-ord-A-in-python.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值