Mark H. Harris
harrismh777 at gmail.com
Mon Mar 3 14:09:31 CET 2014
On Monday, March 3, 2014 3:42:30 AM UTC-6, ast wrote:
> Consider following code:
> >>> A=7
> >>> B=7
> >>> A is B
The names A and B are both bound to the same object (7).
You will discover that this is True for all small ints less
than 257; on CPython3.3.4. I just checked it. :)
Its just more efficient to do this for small ints because they
are immutable (1) and because they are used for frequently (2).
As somebody pointed out last week, don't use "is" for ints and
strings (generally speaking). Value is what's important here,
not identity. My python coding is yet simple and straight
forward enough that I have not had a need yet for "is".
More information about the Python-list