pitfall for your amusement

Andrew Koenig ark at research.att.com
Tue Nov 12 12:39:27 EST 2002


This note is mostly for entertainment purposes.

>>> x = (1, 2, 3)
>>> y = x

>>> x1 = [1, 2, 3]
>>> y1 = x1

>>> x += (4, 5, 6)
>>> x1 += [4, 5, 6]

>>> print y
(1, 2, 3)
>>> print y1
[1, 2, 3, 4, 5, 6]

Yes, I understand why this happens.
No, I'm not proposing to change it.

I do think that people teaching Python should
be sure that their students understand this example.

You may know that I've written fairly extensively
about pitfalls in C and C++; finding examples such
as this one is part of how I understand the essence
of a language.

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list