Summary

We've looked at the built-in numeric types. We've also looked at the vast number of special methods required to invent a new numeric type. Specialized numeric types that integrate seamlessly with the rest of Python is one of the core strengths of the language. That doesn't make the job easy. It merely makes it elegant and useful when done properly.

Design considerations and trade-offs

When working with numbers, we have a multistep design strategy:

  1. Consider the built-in versions of complex, float, and int.
  2. Consider the library extensions such as decimal and fractions. For financial calculations, decimal must be used; there is no alternative.
  3. Consider extending one of the above classes with additional methods or attributes.
  4. Finally, consider a ...

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.