Difference between 'is' and '=='

Clemens Hepper ethrandil at gmx.net
Mon Mar 27 08:49:05 EST 2006


Dan Sommers wrote:
> 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

It's strange: python seem to cache constants from 0 to 99:

for x in xrange(1000):
 if not eval("%d"%x) is eval("%d"%x):
  print x

for me it printed 100-999.

- eth



More information about the Python-list mailing list