different binding behavior

Fredrik Lundh fredrik at pythonware.com
Thu Nov 10 17:21:10 EST 2005


Gabriel Zachmann wrote:

> It seems to me that the following behavior of python (2.4.1) is
> inconsistent:
>
>  >>> a=1
>  >>> b=a
>  >>> a+=1
>  >>> b
> 1
>  >>> a
> 2
>  >>> a=[1,2]
>  >>> b=a
>  >>> b+=[3]
>  >>> a
> [1, 2, 3]
>  >>> b
> [1, 2, 3]
>
> Why was it implemented like this??

assuming that you know that integers cannot modified in place, and
that += on a list is defined to be the same thing as a call to extend,
what did you expect this to do?

</F>






More information about the Python-list mailing list