Easy Tutorial
❮ Python Dictionary Python Calendar ❯

Python ASCII Code and Character Conversion

Python3 Examples

The following code is used to convert between ASCII codes and characters:

Example (Python 3.0+)

# Filename : test.py
# author by : www.tutorialpro.org

# User inputs character
c = input("Please enter a character: ")

# User inputs ASCII code and converts the input to an integer
a = int(input("Please enter an ASCII code: "))

print(c + " has an ASCII code of", ord(c))
print(a, "corresponds to the character", chr(a))

Executing the above code produces the following output:

python3 test.py
Please enter a character: a
Please enter an ASCII code: 101
a has an ASCII code of 97
101 corresponds to the character e

Python3 Examples

❮ Python Dictionary Python Calendar ❯