Postfix/Prefix Operators (++,--)

Greg Ewing (using g2h5dqi002 at
Mon Jun 9 05:59:48 CEST 2003

Peter Hansen wrote:
> Joshua Marshall wrote:
>>List comprehensions let you rebind a variable in an expression, so
>>there is some precedent for this:
> I seem to recall several posts to the effect that this was an 
> unfortunate and/or unexpected and undesirable side-effect of 
> the implementation but that now that it's here, we're sort of
> stuck with it since people believe code already depends on it.

I don't think that's accurate -- I doubt there is a
substantial body of code out there that relies on the
value of a loop variable after a list comprehension

Rather, the current semantics make it possible to
describe the effect of a list comprehension in terms
of an equivalent for-statement. If the binding behaviour
were different, the docs would have to add "except that
it doesn't have a side effect on the loop variable" or
something like that.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list