Python Program to Find ASCII Value of a Character

In this post, we will learn how to find the ASCII value of a character Using Python Programming language.

ASCII stands for American Standard Code for Information Interchange. It is the numeric value given to numbers, characters, letters and symbols to store the value. Each character is assigned a unique 7 bit code.

We will find the ASCII Value of the entered character using the following methods:

  1. Using ord() function
  2. Using chr() function

So, without further ado, let’s begin this tutorial.

Python Program to Find ASCII Value of a Character

# Python Program to Find ASCII Value of a Character
a = input("Enter any character: ")

# Displaying output
print("The ASCII value of char " + a + " is: ", ord(a))

Output

Enter any character: Y
The ASCII value of char Y is:  89

How Does This Program Work ?

a = input("Enter any character: ")

The user is asked to enter a character. The entered character gets stored in a named variable.

print("The ASCII value of char " + a + " is: ", ord(a))

Then, we find the ASCII value of the entered character using the ord() function. The ord() function in python converts a character into its Unicode code value.

Python Program to Find the Character Using ASCII Value

# Python Program to Find ASCII Value of a Character Using chr() function
num = int(input("Enter a number: "))

# Finding the character
ch = chr(num)

# Displaying output
print("Character: " + ch)

Output

Enter a number: 90
Character: Z

Conclusion

I hope after going through this post, you understand how to find the ASCII value of a character using Python Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *