Chapter 2. Integrating Seamlessly with Python Basic Special Methods
There are a number of special methods that permit close integration between our classes and Python. Standard Library Reference calls them basic. A better term might be foundational or essential. These special methods form a foundation for building classes that seamlessly integrate with other Python features.
For example, we need string representations of a given object's value. The base class, object
, has a default implementation of __repr__()
and __str__()
that provides string representations of an object. Sadly, these default representations are remarkably uninformative. We'll almost always want to override one or both of these default definitions. We'll also look at __format__() ...
Get Mastering Object-oriented Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.