Problem with assigning variables of type List
Abhishek Roy
abhishek at ocf.berkeley.edu
Wed Aug 21 15:02:54 EDT 2002
Peter Hansen <peter at engcorp.com> wrote in message news:<3D631501.3A308807 at engcorp.com>...
> Abhishek Roy wrote:
> > 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.
I was just wondering how it's implemented. Since a[1]=a is really
a.__setitem__(1,a), what exactly happens when you call this function
and then later make the comparison a==a[1]?
Abhishek
More information about the Python-list
mailing list