English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this program, you will learn to find the ASCII value of a character and display it.
To understand this example, you should understand the followingPython programmingTopic:
ASCII represents the American Standard Code for Information Interchange.
It is the numerical value assigned to different characters and symbols for computer storage and operation. For example, the ASCII value of the letter 'A' is65.
# Program to find the ASCII value of a given character c = 'p' print("Character '" + c + "The ASCII value of ' is ", ord(c))
Output result
The ASCII value of the character 'p' is 112
Note:To test the program with other characters, please change the character assigned to the variable c.
Here, we use the ord() function to convert the character to an integer (ASCII value). This function returns the Unicode encoding of the character.
Unicode is also an encoding technology that provides a unique number for characters. Although ASCII encodes128characters, but the current Unicode has characters from hundreds of scripts10over 0,000 characters.
It's your turn:Modify the above code usingchr()The function gets the corresponding ASCII value from the Unicode.Characteras shown below.
>>> chr(65) 'A' >>> chr(120) 'x' >>> chr(ord('S')) + 1) 'T'
Here, ord() and chr() are built-in functions. Please visit here to learn more aboutBuilt-in functions of PythonMore information.