ASCII value in Python
In this article, you will learn how to find an ASCII value in Python.
ASCII stands for American Standard Code for Information Interchange. It is a character encoding that uses numeric codes to represent characters. Each letter is assigned a number between 0 and 127. An upper and lower case character are allocated different numbers. For example, the character 'A' is assigned the decimal number 65, while 'a' is assigned decimal 97.
When a PC sends information, the keys you press or the content you send and receive is sent as a bunch of numbers. These numbers represent to the characters you typed or produced. Since the scope of standard ASCII is 0 to 127, it just requires 7 bits or 1 byte of data.
Python provides the ord() method to convert a character to an integer (ASCII value). It accepts a string of length one and returns an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string.
# ASCII Values
x = ord("A")
y = ord("a")
z = ord("2")
p = ord("P")
q = ord("$")
r = ord("*")
# print the unicode values
print("The ASCII value of 'A' is", x)
print("The ASCII value of 'a' is", y)
print("The ASCII value of '2' is", z)
print("The ASCII value of 'P' is", p)
print("The ASCII value of '$' is", q)
print("The ASCII value of '*' is", r)
Output of the above code -
The ASCII value of 'A' is 65
The ASCII value of 'a' is 97
The ASCII value of '2' is 50
The ASCII value of 'P' is 80
The ASCII value of '$' is 36
The ASCII value of '*' is 42
Related Articles
Sentiment Analysis in Python
Python String isalpha() Method
Python YouTube Downloader with Pytube
Python projects for beginners
Pandas Converting Strings to datetime
Pandas fillna multiple columns
Stemming and Lemmatization in Python
Python | Generate QR Code using pyqrcode module
Text Detection and Extraction using OpenCV and OCR
How to Send Text Messages With PHP
Fibonacci Series In Python | Python Program To Print
File Handling in Python
How to convert XML to JSON in Python
Python XML to Dictionary
Serialize Python dictionary to XML