Converting Between ASCII Codes and Characters
The following code demonstrates how to convert between ASCII codes and characters:
Example
# Get user input for a character
c = input("Enter a character: ")
# Get user input for an ASCII code and convert it to an integer
a = int(input("Enter an ASCII code: "))
print(c + " has ASCII code", ord(c))
print(a, "corresponds to the character", chr(a))Example Output:
$ python3 test.py Enter a character: a Enter an ASCII code: 101 a has ASCII code 97 101 corresponds to the character e