Python Program to find ASCII Value of a Character

Write a Python Program to find ASCII Value of a Character with example. In Python, 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 Example 1

This python 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.

# Python Program to find ASCII Value of a Character

ch = 'T'

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

Python ASCII value of a Character output

The ASCII Value of T = 84

Python Program to show ASCII Value of a Character Example 2

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

# Python Program to find ASCII Value of a Character

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

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

Python ASCII value of a Character output

Please enter any Character  :  a
The ASCII Value of a = 97

Python Program to return ASCII Value of a Character Example 3

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.

# Python Program to return ASCII Value of a 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