instance comparison

King animator333 at gmail.com
Thu Jul 24 04:50:06 EDT 2008


I am facing a problem where I am really confused about it.

I am trying to compare to instances using:

if inst1 == inst2

These instances have a overridden method __str__ which returns same
string. The condition result is true although they are different
instances.

If I use:

if id(inst1) == id(inst2)

The results is false. What's happening here?

If I am trying to store this pair in a set where other instances are
already stored, but it's not storing it. Although I am sure that there
is no pair already stored of same but even if Set is comparing by
using string return by __str__ method then it won't.

How do I solve this?

Is this mean when you have overridden __str__ method then it comapre
with results of __str__ or else it will comapre whether they are the
same instances?



More information about the Python-list mailing list