why cannot assign to function call
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Jan 6 21:25:21 EST 2009
On Tue, 06 Jan 2009 13:43:01 -0800, Aaron Brady wrote:
> I think one of the ideas we have trouble communicating is that [1, 2, 3]
> and [4, 5, 6] can be the same object
Not at the same time they can't.
> (using '[:]='), but [1, 2, 3] and [1, 2, 3] don't have to be.
I don't think this is hard to get across, if you think about objects.
You have a list. It's like a box. That box can hold items 1, 2 and 3. You
can replace those items with 4, 5 and 6, and it's still the same box.
Likewise, you can have a box with items 1, 2 and 3 inside it, and a
different box also with items 1, 2 and 3, and they're still different
boxes.
The only tricky thing is that items 1, 2 and 3 can be inside two
different boxes at the same time. There's no obvious real world analogy
to that without the boxes being nested. This ability for objects to be in
two places at once (or even to be inside themselves!) is one of the few
reasons why Python's use of references in the implementation needs to be
mentioned.
--
Steven
More information about the Python-list
mailing list