n = '2'
# Ord(n) gives us the Unicode code point of the given character ('2' = 50)
# hex() produces its hexadecimal equivalent (50 = "0x32")
n_hex = hex(ord(n))
# 0x32
print(n_hex)
# Ord(n) gives us the Unicode code point of the given character ('2' = 50)
n_hex_int = ord(n)
# 50
print(n_hex_int)
首先你的问题是不正确的
n
变量的类型是字符串(长度为1),而不是整数。(因为它对应于十六进制值50,相当于ASCII中的“2”)代码:-
输出:-
相关问题 更多 >
编程相关推荐