In Python, you can retrieve the ASCII value of a character as an integer using the ord() function.
>>> ord('a') 97
To convert the ASCII value back to a character, you can use the chr() function.
>>> chr(97) 'a'
You can also perform arithmetic operations on ASCII values to manipulate characters. For instance, to get the character three positions to the right of 'a' in the ASCII sequence:
>>> chr(ord('a') + 3) 'd'
Note: In Python 2, the unichr() function was used to return Unicode characters. However, in Python 3, chr() can be used for both ASCII and Unicode characters.
The above is the detailed content of How do you get the ASCII value of a character in Python?. For more information, please follow other related articles on the PHP Chinese website!