More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]

Steve Holden steve at
Sun Jan 15 01:08:43 EST 2006

Alex Martelli wrote:
> Steve Holden <steve at> wrote:
>    ...
>>>3. If two objects are equal with "==", does that
>>>  mean their values are the same?
>>Almost universally, yes, although if you know enough about how the 
>>interpreter works "under the hood" you can define the response of 
>>instances of your own classes to the "==" operator (by defining their
>>__eq__ method), and even define a class whose instances aren't equal to
>>anything, even to themselves!
> Hmmm... now this may be just be, but I'm quite vary of saying that,
> since 1 == 1.0 == 1.0+0j, those three objects's values "are the same".
> "Are equal", sure.  But I intuitively see "being the same" as a stronger
> condition than "being equal".
> In mathematics, 1 is not "the same" as 1.0 -- there exists a natural
> morphism of integers into reals that _maps_ 1 to 1.0, but they're still
> NOT "the same" thing.  And similarly for the real-vs-complex case.
> Python may differ -- try using those "equal but not the same numbers" as
> keys into the same dict, and see.  One of the few *surprises* I ever got
> from Python...!-)
> ((I don't think this violates the "introduce no complexity that doesn't
> help understanding" rule -- I think the 1==1.0 case is important!))
Whether it violates the rule or not it's a welcome addition, as was Bengt's.

I just wish Mike Meyer and Steven D'Aprano were close enough that you 
could bang their heads together. In the same playground, perhaps? :-)

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC           
PyCon TX 2006        

More information about the Python-list mailing list