You can download this code by clicking the button below.
This code is now available for download.
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