Python · The Python Data Model · Intermediate · 28 min read
Python Operator Overloading and Comparison: Arithmetic, Reflected Operators, total_ordering and Rich Comparisons
Give your types natural operators without surprises. Learn how binary operators dispatch (left operand, reflected right operand, subclass priority and NotImplemented), in-place operators, unary operators, comparison methods and functools.total_ordering, equality versus ordering, sorting custom objects, numeric tower pitfalls with Decimal, and design rules for readable operator use.
Create an account to start
Create a free account to see what this lesson covers
- Every free lesson in every section, in full
- Track your progress and pick up where you left off
- Free practice questions and an incident simulation
- Takes under a minute: name, email and a password
No card needed. Full access to Python is a paid upgrade you can choose later.