How to covert ASCII to integer in Python?

Lloyd Zusman ljz at asfast.com
Thu Feb 22 13:35:33 EST 2007


"John" <rds1226 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.


-- 
 Lloyd Zusman
 ljz at asfast.com
 God bless you.




More information about the Python-list mailing list