Home » Python Program to Find ASCII Value of Character

Python Program to Find ASCII Value of Character

Learn about Python Program to Find ASCII Value of Character in the below code example. Also, refer to the comments in the code snippet to get a detailed view about what’s actually happening.

In order to convert a character into an ASCII value, we use the ord() method. ord() converts a one-length string ( character ) and returns an integer representing the character’s Unicode code position. For instance, ord(‘a’) yields the integer 97.

Python Program to Find ASCII Value of Character

The below program uses the ord() method to find the ASCII value of the given character.

Program:

# Python program to find ASCII value of character

# character input
ch = input("Enter any character: ")

# printing ascii value of character
print("The ASCII value of " + ch + " is:", ord(ch))

Output:

Enter any character: b
The ASCII value of b is: 98

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : How to Check if a Character is Alphabet in Python