Signup/Sign In

Python Program to print ASCII Value of a Character

In this tutorial, you will learn how to print ASCII value of a character using the Python programing language.

ASCII stands for American Standard Code for Information Interchange. It is a character encoding that uses numeric codes to represent characters and symbols such as upper and lowercase English letters, numbers, and punctuation symbols. Computer stores and manipulates letters and symbols using these codes.

For example, the code should take the following as input and return the ASCII value of the character letter 'A' is 65.

Input- A

Output- ASCII code of A is 65

In this program, we will find and print the ASCII value of a particular character entered by the user at run-time using ord() function.

The ord() method returns the ASCII value of a character passed as its argument. It is a built-in function in the Python library.

Algorithm

Step 1- Take input of a character from the user

Step 2- Declare a variable that will store the ASCII code

Step 3- Call ord() function and pass the input as a parameter

Step 4- Store the value returned by the function in the variable

Step 5- Print the value stored in the variable

Python Program

Look at the complete program given below to understand the implementation of the approach.

#ASCII code of a character

ch = input("Enter character: ")

asc = ord(ch)
print("ASCII code of",ch,"is:", asc)


Enter character: @
ASCII code of @ is: 64

Conclusion

In this tutorial, we learned, how to print the ASCII character of a given character. We can find the Unicode of uppercase, lowercase letters, and also special symbols using this program. We have used a built-in function called ord() to return the Unicode or ASCII of the characters.



About the author:
Nikita Pandey is a talented author and expert in programming languages such as C, C++, and Java. Her writing is informative, engaging, and offers practical insights and tips for programmers at all levels.