conventions/requirements for 'is' vs '==', 'not vs '!=', etc

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon May 19 15:56:26 EDT 2008


On Mon, 19 May 2008 12:39:36 -0700, destroooooy wrote:

> I'm wondering what is the canonical usage of the keywords 'is' and
> 'not' when you're writing conditionals and loops. The one I've been
> following is completely arbitrary--I use the symbols '==', '!=' for
> numerical comparisons and the words 'is', 'not' for everything else.

That's wrong.  Use ``==`` and ``!=`` for testing equality/inequality and
``is`` and ``is not`` for identity testing.  And testing for identity is
quite rare.  Rule of thumb: Use it only for known singletons like `None`.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list