Problem with assigning variables of type List

Michael Hudson mwh at python.net
Wed Aug 21 11:52:08 CEST 2002


Peter Hansen <peter at engcorp.com> writes:

> Abhishek Roy wrote:
> > 
> > "Fredrik Lundh" <fredrik at pythonware.com> wrote in message news:<xiu89.5146$HY3.1421847 at newsc.telia.net>...
> > 
> > >     ... you have to say something like "the object referred to
> > >     by x is passed by reference". Or alternatively, "x is passed
> > >     by value, and that value is a reference to an object". Just
> > >     calling it "pass by reference" or "pass by value" are both
> > >     half true and half false.
> > 
> > I'm still not quite sure what that means but after reading,
> > http://effbot.org/guides/python-objects.htm
> > I experienced a lovely feeling of enlightenment.

Quite: it's much more important to understand how it works than what
it's called.  Call by binding, anyone?  Oh, I just don't care.

> > Just a nagging doubt, using the terminology in the above guide what's going
> > on with:
> > >>> a=[1,2,3]
> > >>> a[1]=a
> > >>> a
> > [1, [...], 3]
> > >>> a==a[1]
> > 1
> 
> You created a recursive object, which contains a reference to
> itself.  Since this goes down infinitely deep, and you can't compare
> infinities, I thought, I wonder whether the "1" is mathematically
> true.  It is certain true according to Python's rules though.

  we're already scrubbing the face of intuition with steel wool,
  setting it on fire, then putting it out with an axe <wink>.
                      -- Tim Peters, on comparing recursive structures

:)

Cheers,
M.

-- 
  That one is easily explained away as massively intricate
  conspiracy, though.            -- Chris Klein, alt.sysadmin.recovery



More information about the Python-list mailing list