Equality and identity
Marius Bernklev
mariube+netnews+ at ifi.uio.no
Tue Mar 30 13:57:04 EST 2004
In python, it seems like immutable objects are equal under both
equality and identity:
>>> 5 == 5
True
>>> 5 is 5
True
>>> "hei" == "hei"
True
>>> "hei" is "hei"
True
But that isn't true for tuples:
>>> (5,2) == (5,2)
True
>>> (5,2) is (5,2)
False
Why not? Are tuples mutable in some way I've missed, or are there
other reasons for this behaviour? To me, it seems natural to concider
(5,2) and (5,2) the same object, just like "5,2" and "5,2".
Marius
--
"Who needs crypto WYCWLT?"
-- William Newman
More information about the Python-list
mailing list