From: Chris Rebert on
On Mon, May 10, 2010 at 4:25 PM, AON LAZIO <aonlazio(a)gmail.com> wrote:
> As subject says, what is the differences of 'is not' and '!='. Confusing..

!= checks value inequality, `is not` checks object identity /
"pointer" inequality
Unless you're doing `foo is not None`, you almost always want !=.

By way of demonstration (using the non-negated versions to be less confusing):
>>> x = [1, 2]
>>> y = [1, 2]
>>> x == y
True
>>> x is y
False
>>> z = x
>>> x is z
True
>>> z is y
False
>>> x.append(3)
>>> x
[1, 2, 3]
>>> y
[1, 2]
>>> z
[1, 2, 3]
>>> x is z
True

Cheers,
Chris
--
http://blog.rebertia.com
From: Christian Heimes on
AON LAZIO wrote:
> As subject says, what is the differences of 'is not' and '!='. Confusing..

"is not" checks if two objects are not identical. "!=" checks if two
objects are not equal.

Example:
Two apples may be equal in size, form and color but they can never be
identical because they are made up from different atoms.

Christian