Dumb noob q: ASCII value of a character

Peter Hansen peter at engcorp.com
Thu Feb 26 13:50:03 EST 2004


Steve Horsley wrote:
> 
> How can I get the ASCII value of a character, e.g. I have:
> 
> str = "A B"
> for index in range(0, len(str)):
>     value = WHAT_GOES_HERE?(str[index])
>     print value
> 
> and I hope to get:
> 65
> 32
> 66
> 
> I know the characters will be printable ASCII.
> But how do I get those ASCII character values from the characters???
> I can't seem to find it in the library reference

It's a good idea to read through all the builtin functions, as
documented in http://www.python.org/doc/current/lib/built-in-funcs.html#built-in-funcs
and keep them in mind.

In this case, ord() (and it's inverse chr()) are what you want.

-Peter



More information about the Python-list mailing list