Does '!=' equivelent to 'is not'

Dan Bishop danb_83 at yahoo.com
Tue Jun 17 05:43:55 CEST 2008


On Jun 16, 10:29 pm, pirata <pir... at mars.invalid> wrote:
> I'm a bit confusing about whether "is not" equivelent to "!="
>
> if a != b:
>   ...
>
> if a is not b:
>   ...
>
> What's the difference between "is not" and "!=" or they are the same thing?

"is not" is the logical negation of the "is" operator, while "!=" is
the logical negation of the "==" operator.  The difference is equality
versus identity.

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> a == b
True
>>> a is b
False



More information about the Python-list mailing list