Can anyone explain a part of a telnet client code to me..

Gabriel Genellina gagsl-py at yahoo.com.ar
Sun Feb 11 00:06:53 EST 2007


En Sun, 11 Feb 2007 00:48:57 -0300, Jia Lu <Roka100 at gmail.com> escribió:

>  I have a program that can telnet to a host.
>  But I cannot understand from [for c in data] part, can anyone explain
> it to me?

data is the received string.
The for statement is used to iterate over a sequence; a string is  
considered a sequence of characters, so it iterates over all the  
characters in the string, one by one.

py> data = "Hello"
py> for c in data:
...   print c, ord(c)
...
H 72
e 101
l 108
l 108
o 111
py>

-- 
Gabriel Genellina




More information about the Python-list mailing list