Dumb noob q: ASCII value of a character

vincent wehren vincent at visualtrans.de
Thu Feb 26 19:57:15 CET 2004

"Steve Horsley" <shoot at the.moon> schrieb im Newsbeitrag
news:c1ldn6$if2$1 at news.freedom2surf.net...
> 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

Hi Steve,

a word of advice: do not use the name of an existing function as identifier
a variable ( I am referring to your usage of str as the name of the
variable - you are reassigning it!!!). But back to your question:
What you're looking for is:

s = "A B"
for c in s:
    print ord(c)


Vincent Wehren

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
> Thanks,
> Steve

More information about the Python-list mailing list