no side effects

Mike Meyer mwm at
Thu Jan 9 01:34:31 CET 2003

Nagy László <nagylzs at> writes:

> Another explanation for a newbie would be this.
> When comparing C++ (or other similar language) and Python for loop,
> the first thing I would mention is that in C++, a for loop is
> terminated by a condition
> but in Python, there is no condition anyway.

Yes there is a condition. It's the end of the list. You can influence
that to get side effects:

l = [1, 2, 3]
for i in l:
   print i
   del l[1:]

will just print "1".

That said, I have *no* idea whether or not this behavior can be
depended upon.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list