[Tutor] Iterating with Range

Alan Gauld alan.gauld at blueyonder.co.uk
Wed Dec 3 19:42:16 EST 2003


> I am trying to iterate through a loop based on the length of a
string. The
> string will be something like this:
>
> FFFFFFFFFFFFFFFFFFFFFFFF // There are 24
> If the string is called parameters[2] why doesn't this work?

Dunno, I didn't look that closely because my first thought was:

>                     for i in range(len(parameters[2])):
>                         port.write(parameters[2][i])


Why not just

                      for c in parameters[2]:
                          port.write(c)
etc...


Using an index here seems unnecessarily complex.

Alan G.




More information about the Tutor mailing list