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 a 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, we are using the ord method to find out the ASCII value of the user-provided character. It reads the character by using the input() method and stored it 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
Similar tutorials :
- Python program to convert a string to an integer
- Python 3 program to convert a decimal number to ternary (base 3)
- Python program to convert kilometers to miles
- Python program to convert Unicode or ASCII value to a character
- Python program to convert an integer number to octal
- Python program to convert meter to yard