Can global variable be passed into Python function?
Mark H. Harris
harrismh777 at gmail.com
Fri Feb 28 03:29:35 CET 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 is b
But...... consider this
a is b
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 is B
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.
More information about the Python-list