[Tutor] Notes on namespaces, scopes, etc
Python
python at venix.com
Sat Jul 29 14:24:45 CEST 2006
On Fri, 2006-07-28 at 23:38 -0400, Kent Johnson wrote:
> Dave Kuhlman wrote:
> > On Thu, Jul 27, 2006 at 05:34:13PM +0100, Alan Gauld wrote:
<snipped>
> Right up to here, I'm standing on my chair and cheering.
> > - Store them in variables.
> >
> Ouch! No! Variables don't store values, they refer to values. Thinking
> of variables as containers doesn't work in Python.
What I told my kids (Dad, Do we really have to learn Python?) was that
variables are sticky notes. The variable name is written on the note
and stuck onto the object.
a = 3
creates an int object with a value of 3 and slaps a sticky note
containing "a" onto the object.
a = 3 + 1
results in a new int object with a value of 4 and the sticky note is
transferred from the "3 object" to the "4 object". (int objects are
immutable, so the "3 object" can not be changed into a "4 object"). If
there are no sticky notes on the "3 object", it can be discarded and the
memory it used to occupy is now available for other objects.
- - - - - - - - - - - - - - - - -
Dave, this may be too simplistic for the document you're writing, but I
think the analogy provides a useful mental image.
--
Lloyd Kvam
Venix Corp
More information about the Tutor
mailing list