[Tutor] (no subject)
Alan G
alan.gauld at freenet.co.uk
Thu May 26 10:15:04 CEST 2005
> S = [chr(x) for x in range (0,256)]
> for x in S:
> print x,
for x in range(256): print chr(x),
> The next step is to use the built-in functin ord() in order to
convert each
> character to an ASCII integer.
That will give you the numbers 0..255
ord() is simply the inverse of chr()
so that
x == ord(chr(x))
> it says that it only take one argument i.e. ord('a'). How could I
execute to
> convert each character into an ASCII integer?
The same as you did for chr(), use a loop:
S = [chr(x) for x in range (0,256)]
for x in S:
print ord(x),
But it will simply print out the list of numbers from 0..255.
Do you have a purpose in mind or are you simply wanting to
observe chr() and ord() in action?
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list