要查看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