Python fractions: rational number arithmetic
Answer: The fractions module provides support for rational number arithmetic. A Fraction is built from a numerator and a denominator; a zero denominator raises ZeroDivisionError. Fraction instances are hashable, and should be treated as immutable.
Examples
from fractions import Fraction
print(Fraction(1, 3) + Fraction(1, 6))
Notes
Reference list
Themodule provides support for rational number arithmetic.zeroA zero denominator raises ZeroDivisionError.Fractioninstances are hashable and should be treated as immutable.
See also
Claims
- id: C1 claim: The module provides support for rational number arithmetic. source: S2 evidence: "The :mod:
!fractionsmodule provides support for rational number arithmetic"
- id: C2 claim: A zero denominator raises ZeroDivisionError. source: S1 evidence: "If denominator is zero, it raises a ZeroDivisionError"
- id: C3 claim: Fraction instances are hashable and should be treated as immutable. source: S2 evidence: "instances are :term:
hashable, and should be treated as immutable"
Sources
- [S1] fractions — Rational numbers. Python docs. https://docs.python.org/3/library/fractions.html . License: PSF-2.0. Accessed 2026-11-18.
- [S2] fractions.rst. CPython docs. https://raw.githubusercontent.com/python/cpython/main/Doc/library/fractions.rst . License: PSF-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, fractions — Rational numbers; CPython docs, fractions.rst. 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 docs, fractions — Rational numbers; CPython docs, fractions.rst. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python fractions: rational number arithmetic." iinventedlight Library, iil:note:actdhhhw, version of 2026-11-18. https://iinventedlight.com/library/notes/python-fractions/. License: CC-BY-4.0.
@misc{iil_note_actdhhhw,
author = {{iinventedlight}},
title = {{Python fractions: rational number arithmetic}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/python-fractions/},
note = {Permanent ID iil:note:actdhhhw. 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-fractions.table.json (table; CC-BY-4.0)
- python-fractions.schema.json (schema; 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-fractions.md.