[Edu-sig] Getting it going

David Scherer dscherer@cmu.edu
Fri, 4 Feb 2000 09:44:29 -0500

I haven't introduced myself yet, and I'm not addressing a very central
issue, but...

> 	* how to explain things in books, lik a variable is a box with a
> 	  sticker on it, a dictionairy is a... a class is a...

A variable in Python isn't a box with a sticker on it, it's just a sticker.
You can stick multiple stickers on the same thing, but there is still only
one of the thing.  This matters when the object is mutable:

a = [3]   # a list [3] with the sticker "a" on it
b = a     # now the list has stickers "a", "b" on it

a[0] = 4  # the list is mutated to [4]
          # and still has stickers "a", "b"

print a   # [4]
print b   # [4]

This is extraordinarily hard to explain with variables as boxes.  How can I
put one object in two boxes, neither of which contains the other?

Of course, you can explain Python's semantics with boxes with stickers
containing pointers, but that's a rather needlessly complicated approach!

Dave Scherer