Explanation of list reference

Ned Batchelder ned at nedbatchelder.com
Fri Feb 14 13:42:21 EST 2014


On 2/14/14 1:08 PM, dave em wrote:
> Hello,
>
> Background:  My twelve y/o son and I are still working our way through Invent Your Own Computer Games with Python, 2nd Edition.
> (We finished the Khan Academy Javascript Tutorials is the extent of our experience)
>
> He is asking a question I am having trouble answering which is how a variable containing a value differs from a variable containing a list or more specifically a list reference.
>
> I tried the to explain as best I can remember is that a variable is assigned to a specific memory location with a value inside of it.  Therefore, the variable is kind of self contained and if you change the variable, you change the value in that specific memory location.
>
> However, when a variable contains a list reference, the memory location of the variable points to a separate memory location that stores the list.  It is also possible to have multiple variable that point to the memory location of the list reference.  And all of those variable can act upon the list reference.
>
> Question:  Is my explanation correct?  If not please set me straight :)
>
> And does anyone have an easier to digest explanation?
>
> Thanks in advance,
> Dave
>

Names in Python refer to values.  Thinking in terms of memory locations 
might just confuse things.

This is my best explanation of the details:
http://nedbatchelder.com/text/names.html

-- 
Ned Batchelder, http://nedbatchelder.com




More information about the Python-list mailing list