Skip to content
Search

Python:fractions

lastmod 2023-01-05created 2022-07-132 edits

Rational numbers

Fraction

Repeating decimals cannot be represented exactly even with fixed-point. In that case, use Fraction from the fractions module to represent them as fractions.

>>> from fractions import Fraction
>>> Fraction('10/3')    # 10을 3으로 나누면 순환소수 3.33333...이지만 분수 3분의 10으로 표현
Fraction(10, 3)

A Fraction is an instance whose numerator and denominator are a pair of integers.

It can be constructed from another rational number or from a string.

That is, Fraction(1, 60000) is 1/60000.

See also

author Zer0 sitemap