Does '!=' equivelent to 'is not'

Asun Friere afriere at
Wed Jun 18 04:04:16 CEST 2008

On Jun 17, 5:33 pm, "Gabriel Genellina" <gagsl-... at>
> En Tue, 17 Jun 2008 02:25:42 -0300, Lie <Lie.1... at> escribió:

> > Basically 'a is b' and 'not(a is b)' is similar to 'id(a) == id(b)'
> > and 'not(id(a) == id(b))'
> No.
> ... The above statement is not. A counterexample:
> py> [] is []
> False
> py> id([])==id([])
> True
But that's not what he said, he used 'a' and 'b' which are names, not
anonymous objects.
Fairer would be,
a = [];b = []
id(a) == id(b)

Morevover, Lie wrote "id(a)==id(b)".  Since there is no need for the
anonymous object to persist following id testing, you cannot guarantee
that you are comparing an id of two objects (as referred to by 'a' and
'b').  Haven't you, in effect, tested id(a) == id(a)?  While this
might be an interesting effect, I doubt that it clarifies the
difference between equivalence and identity testing, in the way Lie's
statement in fact does.

Also in considering what equivalence means in python reference ought
to be made to the __eq__ method.  The original querant may care to
look it up.

More information about the Python-list mailing list