{
    "mode": "pydoc",
    "parameter": "fractions",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/fractions/json",
    "generated": "2026-06-02T14:26:22Z",
    "sections": {
        "NAME": {
            "content": "fractions - Fraction, infinite-precision, real numbers.\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/fractions.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "numbers.Rational(numbers.Real)\nFraction\n",
            "subsections": [
                {
                    "name": "class Fraction",
                    "content": "|  Fraction(numerator=0, denominator=None, *, normalize=True)\n|\n|  This class implements rational numbers.\n|\n|  In the two-argument form of the constructor, Fraction(8, 6) will\n|  produce a rational number equivalent to 4/3. Both arguments must\n|  be Rational. The numerator defaults to 0 and the denominator\n|  defaults to 1 so that Fraction(3) == 3 and Fraction() == 0.\n|\n|  Fractions can also be constructed from:\n|\n|    - numeric strings similar to those accepted by the\n|      float constructor (for example, '-2.3' or '1e10')\n|\n|    - strings of the form '123/456'\n|\n|    - float and Decimal instances\n|\n|    - other Rational instances (including integers)\n|\n|  Method resolution order:\n|      Fraction\n|      numbers.Rational\n|      numbers.Real\n|      numbers.Complex\n|      numbers.Number\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  abs(a)\n|      abs(a)\n|\n|  add(a, b)\n|      a + b\n|\n|  bool(a)\n|      a != 0\n|\n|  ceil(a)\n|      math.ceil(a)\n|\n|  copy(self)\n|\n|  deepcopy(self, memo)\n|\n|  divmod(a, b)\n|      (a // b, a % b)\n|\n|  eq(a, b)\n|      a == b\n|\n|  floor(a)\n|      math.floor(a)\n|\n|  floordiv(a, b)\n|      a // b\n|\n|  ge(a, b)\n|      a >= b\n|\n|  gt(a, b)\n|      a > b\n|\n|  hash(self)\n|      hash(self)\n|\n|  le(a, b)\n|      a <= b\n|\n|  lt(a, b)\n|      a < b\n|\n|  mod(a, b)\n|      a % b\n|\n|  mul(a, b)\n|      a * b\n|\n|  neg(a)\n|      -a\n|\n|  pos(a)\n|      +a: Coerces a subclass instance to Fraction\n|\n|  pow(a, b)\n|      a  b\n|\n|      If b is not an integer, the result will be a float or complex\n|      since roots are generally irrational. If b is an integer, the\n|      result will be rational.\n|\n|  radd(b, a)\n|      a + b\n|\n|  rdivmod(b, a)\n|      (a // b, a % b)\n|\n|  reduce(self)\n|      Helper for pickle.\n|\n|  repr(self)\n|      repr(self)\n|\n|  rfloordiv(b, a)\n|      a // b\n|\n|  rmod(b, a)\n|      a % b\n|\n|  rmul(b, a)\n|      a * b\n|\n|  round(self, ndigits=None)\n|      round(self, ndigits)\n|\n|      Rounds half toward even.\n|\n|  rpow(b, a)\n|      a  b\n|\n|  rsub(b, a)\n|      a - b\n|\n|  rtruediv(b, a)\n|      a / b\n|\n|  str(self)\n|      str(self)\n|\n|  sub(a, b)\n|      a - b\n|\n|  truediv(a, b)\n|      a / b\n|\n|  trunc(a)\n|      trunc(a)\n|\n|  asintegerratio(self)\n|      Return the integer ratio as a tuple.\n|\n|      Return a tuple of two integers, whose ratio is equal to the\n|      Fraction and with a positive denominator.\n|\n|  limitdenominator(self, maxdenominator=1000000)\n|      Closest Fraction to self with denominator at most maxdenominator.\n|\n|      >>> Fraction('3.141592653589793').limitdenominator(10)\n|      Fraction(22, 7)\n|      >>> Fraction('3.141592653589793').limitdenominator(100)\n|      Fraction(311, 99)\n|      >>> Fraction(4321, 8765).limitdenominator(10000)\n|      Fraction(4321, 8765)\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  fromdecimal(dec) from abc.ABCMeta\n|      Converts a finite Decimal instance to a rational number, exactly.\n|\n|  fromfloat(f) from abc.ABCMeta\n|      Converts a finite float to a rational number, exactly.\n|\n|      Beware that Fraction.fromfloat(0.3) != Fraction(3, 10).\n|\n|  ----------------------------------------------------------------------\n|  Static methods defined here:\n|\n|  new(cls, numerator=0, denominator=None, *, normalize=True)\n|      Constructs a Rational.\n|\n|      Takes a string like '3/2' or '1.5', another Rational instance, a\n|      numerator/denominator pair, or a float.\n|\n|      Examples\n|      --------\n|\n|      >>> Fraction(10, -8)\n|      Fraction(-5, 4)\n|      >>> Fraction(Fraction(1, 7), 5)\n|      Fraction(1, 35)\n|      >>> Fraction(Fraction(1, 7), Fraction(2, 3))\n|      Fraction(3, 14)\n|      >>> Fraction('314')\n|      Fraction(314, 1)\n|      >>> Fraction('-35/4')\n|      Fraction(-35, 4)\n|      >>> Fraction('3.1415') # conversion from numeric string\n|      Fraction(6283, 2000)\n|      >>> Fraction('-47e-2') # string may include a decimal exponent\n|      Fraction(-47, 100)\n|      >>> Fraction(1.47)  # direct construction from float (exact conversion)\n|      Fraction(6620291452234629, 4503599627370496)\n|      >>> Fraction(2.25)\n|      Fraction(9, 4)\n|      >>> Fraction(Decimal('1.47'))\n|      Fraction(147, 100)\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties defined here:\n|\n|  denominator\n|\n|  numerator\n|\n|  ----------------------------------------------------------------------\n|  Data and other attributes defined here:\n|\n|  abstractmethods = frozenset()\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from numbers.Rational:\n|\n|  float(self)\n|      float(self) = self.numerator / self.denominator\n|\n|      It's important that this conversion use the integer's \"true\"\n|      division rather than casting one side to float before dividing\n|      so that ratios of huge integers convert without overflowing.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from numbers.Real:\n|\n|  complex(self)\n|      complex(self) == complex(float(self), 0)\n|\n|  conjugate(self)\n|      Conjugate is a no-op for Reals.\n|\n|  ----------------------------------------------------------------------\n|  Readonly properties inherited from numbers.Real:\n|\n|  imag\n|      Real numbers have no imaginary component.\n|\n|  real\n|      Real numbers are their real component.\n"
                }
            ]
        },
        "DATA": {
            "content": "all = ['Fraction']\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/fractions.py\n\n",
            "subsections": []
        }
    },
    "summary": "fractions - Fraction, infinite-precision, real numbers.",
    "flags": [],
    "examples": [],
    "see_also": []
}