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
- id: C1 claim: None of the types in this module are intended to be instantiated. source: S1 evidence: "None of the types defined in this module are intended to be instantiated"
- id: C2 claim: Number is the root of the numeric hierarchy. source: S1 evidence: "The root of the numeric hierarchy"
- id: C3 claim: Use isinstance(x, Number) to check whether x is a number. source: S1 evidence: "use isinstance(x, Number)"
- id: C4 claim: The module defines a hierarchy of numeric abstract base classes. source: S1 evidence: "hierarchy of numeric abstract base classes"
- id: C5 claim: Rational adds numerator and denominator properties. source: S1 evidence: "adds numerator and denominator properties"
- id: C6 claim: The classes progressively define more operations. source: S2 evidence: "progressively define more operations"
Sources
- [S1] numbers — Numeric abstract base classes. Python Software Foundation. https://docs.python.org/3/library/numbers.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] numbers documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/numbers.rst . License: PSF License Version 2. Accessed 2026-11-23.
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
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.},
}
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.
- python-numbers.schema.json (schema; CC-BY-4.0)
- python-numbers.table.json (table; CC-BY-4.0)
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.