Variables versus name bindings [Re: A certainl part of an if() structure never gets executed.]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jun 18 05:05:26 EDT 2013


On Tue, 18 Jun 2013 11:49:36 +0300, Νίκος wrote:

> Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε:
>> Not quite:  a and b _are_ memory addresses,  At the same time, a and b
>> are references to the data (the objects) stored in those memory
>> locations.
>>
>> The distinction is probably more important in languages like C/C++,
>> where the _language_ gives you direct access to, and can manipulate,
>> these memory addresses (through pointers).  Python handles it
>> differently and does not give you this sort of ability, it all occurs
>> "under the hood".  Yes, the id() function will tell you the addresses,
>> but you can't do anything with them other than perhaps compare them.
>> It's really pretty much useless information.
> 
> So, a and b are actual memory addresses.

No, no, no, a thousand times no.


> Does the term of a pointer exist in Python? 

No.


> I mean if print(a) or
> print(b) outputs the object that a and b are linked to, then how do we
> access a's and b's memory locations themselves t create links among
> variables, one pointing to the other and so on?

You cannot. You can only have links between OBJECTS, not between 
VARIABLES. There is no way to have a name "a" set to point to another 
name "b". All you can do is have a name "a" set to refer to the same 
object as "b" has *right now*. If "b" changes to another object, "a" will 
not follow.


> Can a variable point to another variable or variables never point to
> other variables but instead are *only* linked to the objects of those
> var's instead?

Names are *always* linked to objects, not to other names.

a = []
b = a  # Now a and b refer to the same list
a = {} # Now a refers to a dict, and b refers to the same list as before




-- 
Steven



More information about the Python-list mailing list