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 the ASCII Value of a Character

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

ch = 'T'

print("%c = %d" %(ch, ord(ch)))
T = 84

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)))
Python Program to find ASCII Value of a Character using ord()

Find the ASCII Value of a Character using ord() function

If your user entered more than one character, the above-mentioned Python program returns an 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