ASCII Table Generator

  • Share this:

Code introduction


This function takes a string as input, iterates over each character in the string, uses the `ord()` function to get the ASCII value of each character, and generates a table containing the character and its ASCII value.


Technology Stack : String, built-in function

Code Type : Function

Code Difficulty : Beginner


                
                    
def ascii_table(text):
    """
    输入一个字符串,输出该字符串中每个字符及其ASCII值的表格。
    """
    table = ""
    for char in text:
        table += f"{char} | {ord(char)}\n"
    return table