ActiveState Code

Recipe 65117: Converting between ASCII numbers and characters


You want to get the ASCII number of a character, or you want to get the character given by an ASCII number.

Python
1
2
3
4
5
# Get the ASCII number of a character
number = ord(char)

# Get the character given by an ASCII number
char = chr(number)

Discussion

For Unicode characters the builtin functions ord() and unichr() can be used.

Sign in to comment