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) Foo(5) > Foo(2) it will give False, and then when I run the same test again Foo(5) > Foo(2) it will give True?Foo(1), this instantiate a class of Foo, thus it can vary every time. However, if you do a = Foo(1), and use a to compare with b in the same manner, you will always get the same result, b/c nothing has been changed, and you are referring to the same variable with same id
__init__method? Try to show us the complete minimal code.