Explanation of list reference

dave em daveandem2000 at gmail.com
Fri Feb 14 13:08:04 EST 2014


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



More information about the Python-list mailing list