ASCII Table of Input String

  • Share this:

Code introduction


This function takes a string as input and prints the ASCII code and corresponding character for each character in the string.


Technology Stack : Python built-in functions, dictionaries, list comprehensions

Code Type : Function

Code Difficulty : Advanced


                
                    
def ascii_table(string):
    """
    打印输入字符串的ASCII表。
    """
    table = {ord(char): char for char in string}
    for key in sorted(table.keys()):
        print(f"{key}: {table[key]}")