Could you explain this rebinding (or some other action) on "nums = nums"?

Erik python at lucidity.plus.com
Tue Dec 1 17:44:53 EST 2015


Apologies for self-replying,

On 01/12/15 22:34, Erik wrote:
>  what you're asking for is that
> the *container* object whose element is being assigned to is first
> queried as to whether it will accept a mutated element being assigned to
> it before that element is mutated.

What I said above is rubbish. The situation is approximately similar to:

a = [4, 5, 6]
t = ([1, 2, 4], a)
a.append(7)
a.append(8)
a.append(9)

The point is, you're mutating something that an immutable object 
contains. In the example you give, that's caught because of the 
subsequent explicit assignment.

In the example above, it's not caught. But it's the same thing.

E.



More information about the Python-list mailing list