On Fri, Feb 28, 2014 at 1:29 PM, Mark H. Harris <harrismh...@gmail.com> wrote:
> a=1024
> b=a
> b=1024
> a is b
> False

No no no no! They're not pointing to the same integer any more. Now,
if you change the "b=1024" from being a mostly-useless assignment (to
another int with the same value) into being a comparison, then it'll
be safe. But you're assigning "b=a" and then immediately reassigning
"b=1024".

Simple rule of thumb: Never use 'is' with strings or ints. They're
immutable, their identities should be their values. Playing with 'is'
will only confuse you, unless you're specifically going for
introspection and such.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to