[Tutor] question about for loops

Richard D. Moores rdmoores at gmail.com
Thu Jan 7 13:43:26 CET 2010


On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the
section entitled "for Loops" begins:

=========================================
for expression in iterable:
     for_suite
else:
     else_suite

The expression is normally either a single variable or a sequence of
variables, usually in the form of a tuple. If a tuple or list is used
for the expression, each item is unpacked into the expression's items.
======================================

I thought I was quite familiar with for loops, but I don't understand
how the expression can be a sequence of variables, nor what  unpacking
into the expression's items means. Could someone explain this,
preferably with an example?

Thanks,

Dick Moores


More information about the Tutor mailing list