← All notes

numbers: abstract base classes for the numeric tower

Answer: The numbers module defines a hierarchy of numeric abstract base classes. Number is the root of that hierarchy. None of the types defined in this module are intended to be instantiated. To check if x is a number, use isinstance(x, Number).

The root and the tower

None of the types defined in this module are intended to be instantiated.

If you just want to check if an argument x is a number, use isinstance(x, Number).

Number is the root of the numeric hierarchy.

Complex subclasses describe complex numbers and include the operations that work on the built-in complex type, including real, imag, and conjugate(). All except - and != are abstract.

Real adds the operations that work on real numbers, and it also fills in defaults for complex(), real, imag, and conjugate().

Rational subtypes Real and adds numerator and denominator properties.

How the source describes the module

A hierarchy of numeric abstract base classes, which progressively define more operations, is what this module provides.

The numeric tower includes Complex, Real, Rational, and Integral.

numerator and denominator should be Integral instances, in lowest terms, with a positive denominator.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, numbers — Numeric abstract base classes; CPython, numbers documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, numbers — Numeric abstract base classes; CPython, numbers documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:cgtb0mqt

iinventedlight. 2026. "numbers: abstract base classes for the numeric tower." iinventedlight Library, iil:note:cgtb0mqt, version of 2026-11-23. https://iinventedlight.com/library/notes/python-numbers/. License: CC-BY-4.0.

@misc{iil_note_cgtb0mqt,
  author = {{iinventedlight}},
  title = {{numbers: abstract base classes for the numeric tower}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/python-numbers/},
  note = {Permanent ID iil:note:cgtb0mqt. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-numbers.md.