I'm wrong or Will we fix the ducks limp?
steve at pearwood.info
Sun Jun 5 02:37:13 EDT 2016
On Sun, 5 Jun 2016 01:17 pm, Lawrence D’Oliveiro wrote:
> On Saturday, June 4, 2016 at 3:55:12 AM UTC+12, Matt Wheeler wrote:
>> It's best to think of them as names, rather than variables, as names in
>> python don't behave quite how you'll expect variables to if you're coming
>> from some other languages.
> I have made heavy use of Python as well as many other languages, and I
> don’t know what you mean. What “other languages” are you thinking of?
> Are variables like little boxes? Yes they are.
That's *exactly* what variables in Python are not like.
> But they are all the same
> size, while objects may be large (even very large) or small. That is why
> variables hold, not objects, but references to objects.
No they don't. You are confusing the implementation with the programming
Following the assignment:
x = 99
if you print(x), do you see something like "reference 0x12345"? No.
Do you have to dereference that reference to get the value of x? No.
At the Python level, the value of x is 99, not some invisible, untouchable
reference to 99.
There is no analog to dereferencing in Python, nothing like print(x^). You
bind values (that is, objects) directly to names, and names (variables)
hold their value, not a reference to their value.
The fact that for some implementations that is implemented using references
of some sort or another (e.g. pointers in CPython) is an implementation
detail which is irrelevant to the language and its execution model.
More information about the Python-list