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 know the followingPython programmingTopic:
ASCII stands for American Standard Code for Information Interchange.
It is a numerical value assigned to different characters and symbols for computer storage and operation. For example, the ASCII value of letter 'A' is65.
# Program to find the ASCII value of a given character c = 'p' print("Character '" + c + "' has an ASCII value of ", 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 code above usingchr()function retrieves the corresponding ASCII valueCharacteras 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 aboutPython built-in functionsMore information.