On 10/2/06, Arthur Siegel <[EMAIL PROTECTED]> wrote: > The argument I keep making and for which I cannot seem to find any > takers, is that essential to explaining/understanding assignment of a > list to a name, is understanding in the negative - i.e., what it is not. > We are still just teaching basic assignment with regard to a list, and I > maintain that doing so effectively should in part be done in the > negative. What it is not silhouetting better what it is. > > Art >
I'm pretty sure I follow. I might spin this away from "lists" per se, as the multiple references to one object in memory picture is not narrowly about just lists, but any objects, as you well know. A generic way to initialize an object: >>> o = object() The mutability vs. immutability thing is inextricably woven in to the assignment thread, because of what we're able to do with tuples: mutate objects in memory without disturbing their tupuloids i.e. change the contents of a list *in* a tuple. >>> thelist = ['a'] >>> thetuple = (thelist,) >>> thetuple[0][0] = 'b' # not mutating thetuple, but memory object within >>> thetuple (['b'],) When I say something is "semi-esoteric" I'm not arguing that it's discussion be postponed for very long. More it's a rationale for the *design* of Python, i.e. why "copy" requires an import and isn't a builtin. Esoteric books are on a higher shelf -- but that doesn't mean you can't grab them down even on the very first day, if your students are ready to move quickly. Scott mentioned our not being able to see how many handles a mug has, but with the sys module we can: IDLE 1.2b2 >>> import sys >>> a = ['mug of beer'] >>> b = a >>> c = a >>> sys.getrefcount(a) 4 >>> del c >>> sys.getrefcount(a) 3 >>> help(sys.getrefcount) Help on built-in function getrefcount in module sys: getrefcount(...) getrefcount(object) -> integer Return the reference count of object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an argument to getrefcount(). "As a former philosophy major, it disturbs me to think that things disappear when no one is looking at them, but that's exactly what happens in Python. In general, you can simply forget about memory management and let Python clean up after you." -- Mark Pilgrim Kirby _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig