For a group of objects that are number like (called an ordered field) you only need the following things:
And the rest (like subtraction and equality) follow. Obvioulsy, I will also need to add things like __init__
and __str__
, but what type of object can I inherit from that will supply the other operators? Some other operators that I wish would be inferred from the above include:
Take a look at the numbers module. It has abstract base classes for numeric types.
Also take a look at the list of magic methods related to numerical types: http://www.rafekettler.com/magicmethods.html#numeric
While not a complete answer, for comparisons, there is functools.total_ordering
.
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