Python Convert Between ASCII Codes and Characters
The following code converts between ASCII codes and characters:
Example (Python 3.0+)
Filename : test.py
author by : www.runoob.com
The user enters a character
c
=
input
(
"
Please enter a character:
"
)
The user enters an ASCII code, and the entered number is converted to an integer
a
=
int
(
input
(
"
Please enter an ASCII code:
"
)
)
(
c
"
The ASCII code of is
"
,
ord
(
c
)
)
(
a
,
"
The corresponding character is
"
,
chr
(
a
)
)
The output of the code above is:
python3 test.py
请输入一个字符: a
请输入一个ASCII码: 101
a 的ASCII 码为 97
101 对应的字符为 e
Python3 Examples