How do I convert characters into integers?

Paul Rubin http
Wed Dec 15 00:18:57 CET 2004

Markus Zeindl <MarkusZeindl at> writes:

> Now I get every character with a loop:
> <code>
> buffer = ""
> for i in range(len(message)):
>    ch = message[i-1:i]

You mean 
  ch = message[i]
what you have does the wrong thing when i = 0.

> Here is the problem. I got a string with one character and I
> want his ascii representain, for "a" -> 97
> but I want to calculate like iCh = iCh+3 or something else.

iCh = ord(ch)

> The next step is how I convert it back to an char and append it
> to the buffer, but that' no problem.

ch = chr(iCh)

More information about the Python-list mailing list