Clarification on Immutability please

Chris Angelico rosuav at gmail.com
Mon Jan 27 09:23:24 EST 2020


On Tue, Jan 28, 2020 at 1:13 AM Musbur <musbur at posteo.org> wrote:
>
> Am 21.01.2020 19:38 schrieb Chris Angelico:
> > Are you sure that it does? I can't reproduce this. When you slice the
> > first two from a tuple, you create a new tuple, and until the
> > assignment happens, both the new one and the original coexist, which
> > means they MUST have unique IDs.
>
> I'd expect that, too, but an "atomic" reassignment would not contradict
> the documentation.

The way execution works in Python, you first evaluate the object, then
assign it to the target. The new object HAS to exist before the old
one is replaced. There's no such thing as "atomic reassignment" that
simultaneously destroys the old object and assigns a new one. The
slicing will always happen first, and then the assignment.

ChrisA


More information about the Python-list mailing list