ASCII Table Generator

  • Share this:

Code introduction


This function generates an ASCII table, showing the ASCII values and corresponding characters of each character in the given text.


Technology Stack : Built-in libraries

Code Type : Function

Code Difficulty : Beginner


                
                    
def ascii_table(text, width=20):
    """
    Generate an ASCII table for the given text, with each character's ASCII value and its representation.
    """
    table = ""
    for char in text:
        ascii_value = ord(char)
        table += f"{char:3} | {ascii_value:4} | {chr(ascii_value):3}\n"
    return table