'==' vs. 'is' behavior

Duncan Booth duncan at rcp.co.uk
Mon Nov 15 14:08:14 CET 1999

fdrake at acm.org (Fred L. Drake, Jr.) wrote in
<14380.12036.197083.409565 at weyr.cnri.reston.va.us>: 
>  It's working just fine!  Note that the "small" integers (through 99) 
>are always reused, so the "is" relationship will hold.  It's not very
>useful, but reusing the integer objects saves a lot of allocation of
>small numbers, and makes real-world code a lot faster.
It isn't just small integers though that can be reused. Consider:
>>> a = 999
>>> b = 999
>>> print a is b

Put the same lines into a file and run it and it will print 1, or in
interactive mode put the lines into a function definition and again it
prints 1. When compiling anything identical constants are folded

More information about the Python-list mailing list