Scope rule pecularities

Andrew Bennetts andrew-pythonlist at puzzling.org
Fri May 7 03:37:53 EDT 2004


On Fri, May 07, 2004 at 07:12:35AM +0000, Antoon Pardon wrote:
> Op 2004-05-06, Peter Otten schreef <__peter__ at web.de>:
[...]
> >
> > The equivalent a += b would then roughly be a = a.__iadd__(b).
> 
> Well I would say that seems to go against the intention as stated
> in the reference manual. += and associated should attempt the
> operation in place. If you do an operation in place there is
> no need to rebind the variable.

You can't do the operation in-place with immutable values such as numbers
and tuples, though.  So to make "x += 1" work (where is is some integer),
rebinding is necessary.

-Andrew.





More information about the Python-list mailing list