Introduction :

In this tutorial, we will learn how to find the ASCII value of a character in python.The user will enter one character and our program will print the ASCII value.

ASCII or American Standard Code for Information Interchange is the standard way to represent each character and symbol with a numeric value. This example will show you how to print the ASCII value of a character.

 

ord() function :

Python comes with one built-in method ord to find out the unicode value of a character. The syntax of this method is as below :

ord(c)

This method takes one character as parameter and returns the unicode value of that character.

 

Python program to convert character to its ASCII :

c = input("Enter a character : ")

print("The ASCII value of {} is {}".format(c,ord(c)))

You can also download this program from Github

As you can see that we are using ord method to find out the ASCII value of the user provided chracter.The character is read using input() method and stored in the variable ‘c’.

 

Sample Output :

Enter a character : a
The ASCII value of a is 97

Enter a character : A
The ASCII value of A is 65

Enter a character : #
The ASCII value of # is 35

Enter a character : *
The ASCII value of * is 42

Enter a character : $
The ASCII value of $ is 36

Enter a character : )
The ASCII value of ) is 41

Categories: python

Leave a Reply

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