is None or == None ?

sturlamolden sturlamolden at
Sat Nov 7 23:22:28 CET 2009

On 6 Nov, 14:35, "Alf P. Steinbach" <al... at> wrote:

> As I understand it, 'is' will always work and will always be efficient (it just
> checks the variable's type), while '==' can depend on the implementation of
> equality checking for the other operand's class.

'==' checks for logical equality. 'is' checks for object identity.

None is a singleton of type NoneType. Since None evaluates to True
only when compared against itself, it is safe to use both operators.

More information about the Python-list mailing list