Difference between 'is' and '=='

Felipe Almeida Lessa felipe.lessa at gmail.com
Mon Mar 27 09:08:36 EST 2006


Em Seg, 2006-03-27 às 08:23 -0500, Dan Sommers escreveu:
> 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
>     >>> 

Not those kind of constants, but this one:

Python 2.4.2 (#2, Nov 20 2005, 17:04:48)
[GCC 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> CONST = 123456789
>>> a = CONST
>>> a == CONST
True
>>> a is CONST
True
>>>

-- 
Felipe.




More information about the Python-list mailing list