Summary
We've looked at a number of basic special methods, which are essential features of any class that we design. These methods are already part of every class, but the defaults that we inherit from the object may not match our processing requirements.
We'll almost always need to override __repr__(), __str__(), and __format__(). The default implementations of these methods aren't very helpful at all.
We rarely need to override __bool__() unless we're writing our own collection. That's the subject of Chapter 7, Creating Containers and Collections.
We often need to override comparison and __hash__() methods. These definitions are suitable for simple immutable objects, but are not at all appropriate for mutable objects. We may not need to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access