Semantics of ==

Axel Boldt axelboldt at yahoo.com
Tue Mar 16 18:38:39 EST 2004


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



More information about the Python-list mailing list