Python Program to Print ASCII Value of a Character

Write a python program to print ascii value of a character. ord() in python coverts the given string of length one into an integer representing the unicode of the character.

For example, ord(‘a’) returns the integer 97.

Python program to print ascii value of a character

# accept character from user
ch = input("Enter any character: ")

# store a character
ch = 'a'

# print the ASCII value of character in variable ch
print("The ASCII value of '" + ch + "' is", ord(ch))

Output:

The ASCII value of 'a' is 97 

Comments