Can global variable be passed into Python function?
Chris Angelico
rosuav at gmail.com
Thu Feb 27 23:43:23 EST 2014
On Fri, Feb 28, 2014 at 1:29 PM, Mark H. Harris <harrismh777 at 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
More information about the Python-list
mailing list