Python program to find ASCII value of character
In this post, you will learn how to find the ASCII value of a character in the Python programming language.
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-case and lower-case character are allocated different numbers. For example, the character 'A' is assigned the decimal number 65, while 'a' is assigned the decimal 97.
When a PC sends information, the keys you press or the content you send and receive are sent as a bunch of numbers. These numbers represent the characters you typed or produced. Since the scope of standard ASCII is 0 to 127, it only requires 7 bits, or 1 byte, of data.
Python ord() method
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.
Syntax-ord(character)
Find ASCII value of character
# Python program to find
# ASCII value of character
x = input("Please enter a character: ")
print ("The ASCII value of '" + x + "' is ", ord(x))
Output of the above code:
Please enter a character: A
The ASCII value of 'A' is 65
Please enter a character: b
The ASCII value of 'b' is 98
Please enter a character: k
The ASCII value of 'k' is 107
Please enter a character: Z
The ASCII value of 'Z' is 90
Please enter a character: M
The ASCII value of 'M' is 77
Related Articles
Python program to print all even numbers between 1 to 100
Pandas DataFrame to JSON
Prettytable in Python
Count consonants in a string Python
Python split strings by comma
Count vowels in a string Python
Replace multiple characters Python
Convert array to list Python
Python loop through list
Difference between tuple and list in Python
Convert string to list Python
Remove last element from list Python
Convert list to string Python
Convert Python list to numpy array
Remove element from list Python
Python dict inside list
Check if list is empty Python
Python iterate list with index
Python iterate list with index
Python split string by comma
Printing Simple Diamond Pattern in Python
Stemming and Lemmatization in Python
Python | Generate QR Code using pyqrcode module