X is confusing
p_s_oberoi at hotmail.com
Tue Jul 6 23:10:09 CEST 2004
>> I mean how do you explain 'is' or 'id(X)' to the first time
>> programmer when it does this to you.
A first time programmer should never need to use 'is', with the exception
of '... is None' (and even that can be replaced by == as far as a first
time programmer is concerned).
An understanding of the meaning of 'is' requires understanding the concept
of objects, and the difference between object equality and object
identity. Once those concepts are known, it should be easy to explain
that since low-valued integers are frequently used, python creates them
once and reuses them when needed, whereas for larger numbers a new object
is created every time.
More information about the Python-list