Problem with assigning variables of type List

Peter Hansen peter at engcorp.com
Wed Aug 21 06:20:17 CEST 2002


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.
> 
> 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.

-Peter



More information about the Python-list mailing list