Confusion: assignments create object references.

Terry Reedy tjreedy at udel.edu
Fri Apr 11 13:35:09 EDT 2003


"Havens, Peter" <Peter.Havens at Level3.com> wrote in message
news:mailman.1050080058.23175.python-list at python.org...
>I'm a silly rabbit. I hand copied the test incorrectly.

Many of us have learned to always cut&paste -- carefully.

The real test was:

>>> L = 1
>>> M = L

This binds M to an (immutable) int object with value 0

>>> M = 0

The (re)binds M to an (immutable) int object with value 1.  This has
nothing to do with L.

>>> L
1

>Those are the real results (I double checked), but now I'm really
confused. Why does the >former test (the one I lied about) above give
expected results, and the later doesn't?

Because your expectation is still wrong.  Modifying a (mutable) object
(by rebinding one of its slots) is different from rebinding a name to
another object.

Terry J. Reedy






More information about the Python-list mailing list