26.7 Comparing Objects: __eq__, __lt__, and @total_ordering
The Need for Custom Comparisons By default, Python’s == and != operators for objects compare their identities—that is, they check if two variables refer to the exact same object in memory, behaving like the is operator. This is rarely the desired behavior for data-centric classes. For instance, two distinct BankAccount objects with the same account number and balance should be considered equal for most application logic, even though they are separate instances. To enable this value-based comparison, you must provide your own implementation by defining the __eq__ method.