newbie problem with 'ord' function

Jesper Hertel jh at cddk.dk
Mon Dec 4 09:55:55 EST 2000


Here is another way to do it:


digits = "0123456789"

print "NUMBER", "ASCII Code"

for digit in digits:
    print digit, ord(digit)


This works because a string in Python can also act as a list of characters.
You could expand the 'digits' string to contain other characters than
digits.

/Jesper


"dr. franken" <oniet at poczta.onet.pl> wrote in message
news:90b53f$31r$1 at news.tpi.pl...
> >    numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
> >    NUMBER   ASCII Code
> > 1 49
> > 2 50 etc.
> >
> > What would do the trick?
>
> for x in numbers:
>   print x, ord(`x`)  #not 'x' but `x`!
>
> --
> franken
>
>





More information about the Python-list mailing list