I am writing a Fractions class and while messing around I noticed this:
>>> class Test:
def __init__(self):
pass
>>> Test()>Test()
True
>>> Test()>Test()
False
Why is this?
Put simply, your comparisons aren't directly on the data of the class, but the instance of class itself (id(Foo(1))), because you have not written it's comparisons explicitly.
It compares the id of the instances, thus sometimes it's True and other times it's False.
Foo(1)
=> <__main__.Foo instance at 0x2a5684>
Foo(1)
=> <__main__.Foo instance at 0x2a571c>
Foo(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With