[Tutor] Tuples, Dictionarys and mutable vs. immutable

Sheila King sheila@thinkspot.net
Sun, 25 Feb 2001 22:35:33 -0800


OK, another question.

Here is something I ran on IDLE. A fresh session:

Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.6 -- press F1 for help
>>> x=1
>>> id(x)
8400864
>>> y=1
>>> id(y)
8400864
>>> del x
>>> del y
>>> z = 1
>>> id(z)
8400864
>>> id(1)
8400864
>>> id('a')
8532752
>>> id(('a', 'b', 'c'))
8756556
>>> z=('a', 'b', 'c')
>>> id(z)
8756556
>>> 

OK, question:

See how, even before I assigned the tuple ('a', 'b', 'c') to any variable, in
fact, the first time I mentioned it in the shell session, it already had an
id(). Which, means it had a memory location.

Does Python create that location and assign the object to it as soon as I
mention it? Was that memory assignment made when I typed:
>>> id(('a', 'b', 'c'))

I'm trying to figure out the way this all works in the memories. I did read
http://www.python.org/doc/current/ref/objects.html

but it still isn't clear to me how this works. (I'm sort of working through
"Diving into Python" right now, in slow motion...)

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/