In this tutorial, we will learn about how to get the ASCII value of any character in Python with this easy-to-follow guide. This tutorial will make you understand it easily with a simple example.
ASCII stands for American Standard Code for Information Interchange. These ASCII values are nothing but the representations of characters in computers as a alphanumeric data. It is operated by the Internet Assigned Numbers Authority(IANA). It is a seven-bit code based on the English alphabet. It stands for 128 English characters in number type from 0 to 127. It is a encoding method, mostly used in telecommunications, computers and other related devices.
In this real world, we can read, write, and understand the text which is there on the paper, also we can write using a pen and read what is there on the paper. However, when it comes to digital communication, machines does not understand letters and symbols as well as humans do. Rather, they will covert the data in the form of binary code, which is made up of 1’s and 0’s. Here’s when ASCII values are useful.
Get ASCII value of any character in Python
Now, we will learn about how to write a code in Python, to get the ASCII value of any character that we gave to the machine.
However, we will create a variable first to store the value or to hold the given value. Let the variable be “word”. Word will store a character, and that character’s ASCII value is known by using the built-in ord() function.
Here is an easy example code for how to get the ASCII value of any character in Python.
word = 'Z' ASCIIvalue = ord(word) print(f"The ASCII value of '{word}' is {ASCIIvalue}")
The output for the above code is given below:
OUTPUT :
The ASCII value of 'Z' is 90
We got the ASCII value of ‘Z’ as 90. As a result, the needed output is obtained.