I read this thread about converting the alphabet to numbers but I don't understand how to convert the numbers back into letters.
I would appreciate if someone could expand on that, especially and more specifically, the chr()
function described in the thread. I've already tried searching for the chr
function but there aren't many tutorials for it.
Asked
Active
Viewed 1.7e+01k times
42

martineau
- 119,623
- 25
- 170
- 301

user2734815
- 431
- 1
- 4
- 7
-
3[Here's a link to the documentation of `chr()`](http://docs.python.org/2/library/functions.html#chr) – TerryA Aug 31 '13 at 04:21
-
1I think this question is not a duplicate because the number `27` is not coverted. It should be for example `AA` – nowox Aug 11 '19 at 12:37
1 Answers
83
If you have a number, for example 65, and if you want to get the corresponding ASCII character, you can use the chr
function, like this
>>> chr(65)
'A'
similarly if you have 97,
>>> chr(97)
'a'
EDIT: The above solution works for 8 bit characters or ASCII characters. If you are dealing with unicode characters, you have to specify unicode value of the starting character of the alphabet to ord
and the result has to be converted using unichr
instead of chr
.
>>> print unichr(ord(u'\u0B85'))
அ
>>> print unichr(1 + ord(u'\u0B85'))
ஆ
NOTE: The unicode characters used here are of the language called "Tamil", my first language. This is the unicode table for the same http://www.unicode.org/charts/PDF/U0B80.pdf

thefourtheye
- 233,700
- 52
- 457
- 497
-
1You could probably note that, this is an ASCII table specific solution. – László Papp Aug 31 '13 at 04:23
-
1@LaszloPapp You are correct. Considering the thread OP quoted, I assumed that we are dealing with english alphabets. – thefourtheye Aug 31 '13 at 04:25
-
2Also, you could explain to the readers what the meaning of '7' is. It may not be straight forward. – László Papp Aug 31 '13 at 04:26
-
1