different binding behavior
David Wahler
dwahler at gmail.com
Thu Nov 10 16:59:48 EST 2005
Gabriel Zachmann wrote:
> It seems to me that the following behavior of python (2.4.1) is inconsistent:
[snip]
> Why was it implemented like this??
Lists are mutable objects; integers are not. For a list, a += b is
equivalent to a.__iadd__(b), which is an in-place modification.
For an integer, no __iadd__ method is provided, so a += b is equivalent
to a = a.__add__(b), which is a rebinding operation rather than a
modification.
This question (or variants thereof) is asked on an almost daily basis;
please search before posting.
-- David
More information about the Python-list
mailing list