Show the ASCII value of a character in Python
Here, in this tutorial, we will see the ASCII value of a character in the Python language.
Basically, ASCII means American Standard Code for International Interchange which is a character encoding standard. This ASCII code represents text in computers as computers can’t understand the text and they understand binary code only.
You might think, how the text that we give to our computer is understood by it?
So, initially, the text is converted to numbers by ASCII code. The computer can understand the ASCII code. This ASCII is a character representation scheme based on 7 digits.
Every character on the keyboard has its own ASCII representation. For example, the value of ‘V’ in ASCII is 86 when represented in decimal value. Similarly, the value of ‘a’ in ASCII is 1100001 that is 97 in decimal.
The ASCII code is written not only for numbers and alphabets, it is written for special characters also. This ASCII code is written for nonprintable characters and printable characters. Nonprintable characters like (ESCAPE, CANCEL, NULL, DOWN ARROW, UP ARROW, and so on), whereas printable characters like alphabets, numbers, special characters(@,$,# and so on).
Now, let us see the ASCII value of a specific character.
To know the ASCII value of a character in Python
Initially, let us give the input character to know the ASCII value of a given input character.
To give the input character you need to have knowledge of how to give input in Python.
To understand this code you must know the Built-in functions in Python programming.
t=input("Enter a character to get the ASCII value") print("The ASCII value of the character is ",ord(t))
Here, we used the function ord() which is a Built-in function. As we used this function here to convert a character type value to integer type value.
We used this function here because we need to know the value of a character.
Enter the character for which you want to know the ASCII value p The ASCII value of the character is 112
Let us see another example:
print("The ASCII value of V is",ord('V'))
The ASCII value of V is 86
This ord() function is a Built-in function. It returns ‘integer’ value when a ‘string’ of length one is given. Here, the integer value represents the Unicode point of the character.
- Remove multiple spaces from a string in Python
- Count the number of capital letters in a string in Python