Difference between 'is' and '=='

Dan Sommers me at privacy.net
Mon Mar 27 08:23:40 EST 2006


On Mon, 27 Mar 2006 14:52:46 +0200,
Joel Hedlund <joel.hedlund at gmail.com> wrote:

> ... According to PEP8 (python programming style guidelines) you should
> use 'is' when comparing to singletons like None. I take this to also
> include constants and such ...

This does *not* also mean constants and such:

    Python 2.4.2 (#1, Feb 22 2006, 08:02:53) 
    [GCC 4.0.1 (Apple Computer, Inc. build 5247)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> a = 123456789
    >>> a == 123456789
    True
    >>> a is 123456789
    False
    >>> 

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list