You can download this code by clicking the button below.
This code is now available for download.
This function takes a string as input and prints the ASCII value and corresponding character for each character in the string.
Technology Stack : Python built-in libraries
Code Type : Function
Code Difficulty :
def ascii_table(string):
"""
打印一个字符串的ASCII表。
"""
ascii_dict = {ord(char): char for char in string}
ascii_dict = dict(sorted(ascii_dict.items()))
for key, value in ascii_dict.items():
print(f"{key:3d} | {value}")
# 代码所属类型: 函数
# 代码难度: 初学
# 代码含义解释: 该函数接受一个字符串作为输入,然后打印出该字符串中每个字符的ASCII值和对应的字符。
# 代码所使用到的包和技术栈: Python内置库
# 代码含义解释: This function takes a string as input and prints the ASCII value and corresponding character for each character in the string.
# 代码所使用到的包和技术栈: Python built-in libraries