Python Program to find ASCII Value of a Character

Write a Python Program to find the ASCII Value of a Character with an example. In this language, every character has its own ASCII value (Nothing but an integer). For example, the ASCII value for the A is 65.

Python Program to find ASCII Value of a Character

This program returns the ASCII value of T. Please refer ASCII Table article in Python to understand the list of ASCII characters and their decimal, Hexadecimal, and Octal numbers.

ch = 'T'

print("The ASCII Value of %c = %d" %(ch, ord(ch)))
The ASCII Value of T = 84

Python Program to find ASCII Value of a Character Example 2

This program to return ASCII values is the same as above. However, this time we are allowing the user to enter their own character.

ch = input("Please enter any Character  :  ")

print("The ASCII Value of %c = %d" %(ch, ord(ch)))
Please enter any Character  :  a
The ASCII Value of a = 97

Python Program to find ASCII Value of a Character using ord

If your user entered more than one character, then the above python program return error. In this program, we are using the index position to return the ASCII value of the first character.

ch = input("Please enter any Character  :  ")

print("The ASCII Value = %d" %ord(ch[0]))
Python Program to find ASCII Value of a Character 3

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.