Semantics of ==

John Roth newsgroups at jhrothjr.com
Wed Mar 17 01:07:27 CET 2004


"Axel Boldt" <axelboldt at yahoo.com> wrote in message
news:40200384.0403161538.7407d9e2 at posting.google.com...
> Still trying to understand "=="... It appears as if two equal objects
> can become unequal if you perform the same operations on them:
>
>   >>> l=[1]
>   >>> s=l
>   >>> l.append(s)
>   >>> w=[1]
>   >>> r=[1,w]
>   >>> w.append(r)
>   >>> s
>   [1, [...]]
>   >>> w
>   [1, [1, [...]]]
>   >>> s==w
>   True
>
> Note that they're equal, yet are printed differently.
>
>   >>> s[0]=2
>   >>> w[0]=2
>   >>> s==w
>   False
>
> All of a sudden they have become unequal.
>
> Axel

You've got a recursive structure! I originally thought
that the [...] was something you'd done to the printout,
but it isn't.

I think the original True is a bug. It's getting confused
by the recursion.

John Roth





More information about the Python-list mailing list