no side effects
Mike Meyer
mwm at mired.org
Wed Jan 8 19:34:31 EST 2003
Nagy László <nagylzs at freemail.hu> 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
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list