[Python-Dev] A proposal has surfaced on comp.lang.pythontoredefine "is"

Andrew Koenig ark at acm.org
Thu Mar 18 11:40:18 EST 2004


> Is "mutually substitutable" a fancy way of saying "equal"?  In other
> words,
> why would "x is y" be preferred over "x == y"?

"Mutually substitutable" is a fancy way of saying "equal" for immutable
objects only.  For mutable objects, or for immutable objects with mutable
components, the situation is more complicated.  For example:

	a = []
	b = []
	x = (a, a)
	y = (b, b)

Here, x and y are equal but not mutably substitutable, because if I execute
x[0].append(42), it changes x but not y.  On the other hand, if a and b were
() rather than [], then x and y would be mutually substitutable because
there would be no way to distinguish x from y except by their id.





More information about the Python-Dev mailing list