pitfall for your amusement

Andrew Koenig ark at research.att.com
Tue Nov 12 13:52:41 EST 2002


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

>> >>> x += (4, 5, 6)

Gustavo> Hey, shouldn't this raise an exception?

Perhaps it should, but it doesn't:  If x is a tuple,

	x += y

is equivalent to

	x = x + y

which creates a brand-new object and (re)binds x to it.

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




More information about the Python-list mailing list