要查看ASCII码,可以使用内置函数ord()
来获取字符的ASCII码值。示例代码如下:
# 查看字符'A'的ASCII码
ascii_value = ord('A')
print(f"The ASCII value of 'A' is {ascii_value}")
运行以上代码将输出:
The ASCII value of 'A' is 65
另外,可以使用chr()
函数来将ASCII码值转换为对应的字符。示例代码如下:
# 将ASCII码值65转换为对应的字符
character = chr(65)
print(f"The character with ASCII value 65 is {character}")
运行以上代码将输出:
The character with ASCII value 65 is A