Can global variable be passed into Python function?
Mark H. Harris
harrismh777 at gmail.com
Thu Feb 27 21:29:35 EST 2014
On Thursday, February 27, 2014 8:07:20 PM UTC-6, Steven D'Aprano wrote:
> If they point to the same piece of memory -- which, by the way, can be
> moved around if the garbage collector supports it -- then A is B cannot
> possibly return False.
>
hi Steve, long time, yes, my whole point exactly. And we all know what python is doing under the covers for small ints like 0 - 256 ... in which case consider the following:
a=128
b=a
b=128
a is b
True
But...... consider this
a=1024
b=a
b=1024
a is b
False
For small ints below a certain value (257) A is B will always be True.... but now for ints above that value, as I've shown,
A=257
B=A
B=257
A is B
False
But for the variable discussion (like in BASIC, or even C) A=128, B=A, A and B are two pieces of memory that both happen to be variables containing different pieces of memory. For python, the references to small ints (as above) will almost always point to the same int object for each reference; hence the need for reference counts.
Folks that think of assignment in python with a BASIC, or even C, mentality will have trouble understanding the difference between "==" and "is" and why... and they won't get reference counting.
Cheers
More information about the Python-list
mailing list