How to covert ASCII to integer in Python?

MRAB google at mrabarnett.plus.com
Thu Feb 22 16:13:52 EST 2007


On Feb 22, 6:35 pm, Lloyd Zusman <l... at asfast.com> wrote:
> "John" <rds1... at sh163.net> writes:
> > I just found ord(c), which convert ascii to integer.
>
> > Anybody know what the reverse is?
>
> The inverse of "ord" is "chr":
>
>   % python
>   Python 2.5 (r25:51908, Jan  5 2007, 00:12:45)
>   [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
>   Type "help", "copyright", "credits" or "license" for more information.
>   >>> ord('i')
>   105
>   >>> chr(105)
>   'i'
>   >>>
>
> IIRC, the first use of the names "ord" and "chr" for these functions
> appeared in the Basic language in the 1960's ... in case anyone is
> interested in this bit of historical trivia.
>
In the versions of Basic that I've seen they were ASC (clearly ASCII)
and CHR$. I first saw ord in Pascal.




More information about the Python-list mailing list