Markdown Format | JSON API | MCP Server Tool
Help on module numbers: NAME numbers - Abstract Base Classes (ABCs) for numbers, according to PEP 3141. MODULE REFERENCE https://docs.python.org/3.10/library/numbers.html The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above. DESCRIPTION TODO: Fill out more detailed documentation on the operators. CLASSES builtins.object Number Complex Real Rational Integral class Complex(Number) | Complex defines the operations that work on the builtin complex type. | | In short, those are: a conversion to complex, .real, .imag, +, -, | *, /, **, abs(), .conjugate, ==, and !=. | | If it is given heterogeneous arguments, and doesn't have special | knowledge about them, it should fall back to the builtin complex | type as described below. | | Method resolution order: | Complex | Number | builtins.object | | Methods defined here: | | __abs__(self) | Returns the Real distance from 0. Called for abs(self). | | __add__(self, other) | self + other | | __bool__(self) | True if self != 0. Called for bool(self). | | __complex__(self) | Return a builtin complex instance. Called for complex(self). | | __eq__(self, other) | self == other | | __mul__(self, other) | self * other | | __neg__(self) | -self | | __pos__(self) | +self | | __pow__(self, exponent) | self**exponent; should promote to float or complex when necessary. | | __radd__(self, other) | other + self | | __rmul__(self, other) | other * self | | __rpow__(self, base) | base ** self | | __rsub__(self, other) | other - self | | __rtruediv__(self, other) | other / self | | __sub__(self, other) | self - other | | __truediv__(self, other) | self / other: Should promote to float when necessary. | | conjugate(self) | (x+y*i).conjugate() returns (x-y*i). | | ---------------------------------------------------------------------- | Readonly properties defined here: | | imag | Retrieve the imaginary component of this number. | | This should subclass Real. | | real | Retrieve the real component of this number. | | This should subclass Real. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset({'__abs__', '__add__', '__complex__', ... | | __hash__ = None class Integral(Rational) | Integral adds methods that work on integral numbers. | | In short, these are conversion to int, pow with modulus, and the | bit-string operations. | | Method resolution order: | Integral | Rational | Real | Complex | Number | builtins.object | | Methods defined here: | | __and__(self, other) | self & other | | __float__(self) | float(self) == float(int(self)) | | __index__(self) | Called whenever an index is needed, such as in slicing | | __int__(self) | int(self) | | __invert__(self) | ~self | | __lshift__(self, other) | self << other | | __or__(self, other) | self | other | | __pow__(self, exponent, modulus=None) | self ** exponent % modulus, but maybe faster. | | Accept the modulus argument if you want to support the | 3-argument version of pow(). Raise a TypeError if exponent < 0 | or any argument isn't Integral. Otherwise, just implement the | 2-argument version described in Complex. | | __rand__(self, other) | other & self | | __rlshift__(self, other) | other << self | | __ror__(self, other) | other | self | | __rrshift__(self, other) | other >> self | | __rshift__(self, other) | self >> other | | __rxor__(self, other) | other ^ self | | __xor__(self, other) | self ^ other | | ---------------------------------------------------------------------- | Readonly properties defined here: | | denominator | Integers have a denominator of 1. | | numerator | Integers are their own numerators. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset({'__abs__', '__add__', '__and__', '__c... | | ---------------------------------------------------------------------- | Methods inherited from Real: | | __ceil__(self) | Finds the least Integral >= self. | | __complex__(self) | complex(self) == complex(float(self), 0) | | __divmod__(self, other) | divmod(self, other): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __floor__(self) | Finds the greatest Integral <= self. | | __floordiv__(self, other) | self // other: The floor() of self/other. | | __le__(self, other) | self <= other | | __lt__(self, other) | self < other | | < on Reals defines a total ordering, except perhaps for NaN. | | __mod__(self, other) | self % other | | __rdivmod__(self, other) | divmod(other, self): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __rfloordiv__(self, other) | other // self: The floor() of other/self. | | __rmod__(self, other) | other % self | | __round__(self, ndigits=None) | Rounds self to ndigits decimal places, defaulting to 0. | | If ndigits is omitted or None, returns an Integral, otherwise | returns a Real. Rounds half toward even. | | __trunc__(self) | trunc(self): Truncates self to an Integral. | | Returns an Integral i such that: | * i>0 iff self>0; | * abs(i) <= abs(self); | * for any Integral j satisfying the first two conditions, | abs(i) >= abs(j) [i.e. i has "maximal" abs among those]. | i.e. "truncate towards 0". | | conjugate(self) | Conjugate is a no-op for Reals. | | ---------------------------------------------------------------------- | Readonly properties inherited from Real: | | imag | Real numbers have no imaginary component. | | real | Real numbers are their real component. | | ---------------------------------------------------------------------- | Methods inherited from Complex: | | __abs__(self) | Returns the Real distance from 0. Called for abs(self). | | __add__(self, other) | self + other | | __bool__(self) | True if self != 0. Called for bool(self). | | __eq__(self, other) | self == other | | __mul__(self, other) | self * other | | __neg__(self) | -self | | __pos__(self) | +self | | __radd__(self, other) | other + self | | __rmul__(self, other) | other * self | | __rpow__(self, base) | base ** self | | __rsub__(self, other) | other - self | | __rtruediv__(self, other) | other / self | | __sub__(self, other) | self - other | | __truediv__(self, other) | self / other: Should promote to float when necessary. | | ---------------------------------------------------------------------- | Data and other attributes inherited from Complex: | | __hash__ = None class Number(builtins.object) | All numbers inherit from this class. | | If you just want to check if an argument x is a number, without | caring what kind, use isinstance(x, Number). | | Data and other attributes defined here: | | __abstractmethods__ = frozenset() | | __hash__ = None class Rational(Real) | .numerator and .denominator should be in lowest terms. | | Method resolution order: | Rational | Real | Complex | Number | builtins.object | | Methods defined here: | | __float__(self) | float(self) = self.numerator / self.denominator | | It's important that this conversion use the integer's "true" | division rather than casting one side to float before dividing | so that ratios of huge integers convert without overflowing. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | denominator | | numerator | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset({'__abs__', '__add__', '__ceil__', '__... | | ---------------------------------------------------------------------- | Methods inherited from Real: | | __ceil__(self) | Finds the least Integral >= self. | | __complex__(self) | complex(self) == complex(float(self), 0) | | __divmod__(self, other) | divmod(self, other): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __floor__(self) | Finds the greatest Integral <= self. | | __floordiv__(self, other) | self // other: The floor() of self/other. | | __le__(self, other) | self <= other | | __lt__(self, other) | self < other | | < on Reals defines a total ordering, except perhaps for NaN. | | __mod__(self, other) | self % other | | __rdivmod__(self, other) | divmod(other, self): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __rfloordiv__(self, other) | other // self: The floor() of other/self. | | __rmod__(self, other) | other % self | | __round__(self, ndigits=None) | Rounds self to ndigits decimal places, defaulting to 0. | | If ndigits is omitted or None, returns an Integral, otherwise | returns a Real. Rounds half toward even. | | __trunc__(self) | trunc(self): Truncates self to an Integral. | | Returns an Integral i such that: | * i>0 iff self>0; | * abs(i) <= abs(self); | * for any Integral j satisfying the first two conditions, | abs(i) >= abs(j) [i.e. i has "maximal" abs among those]. | i.e. "truncate towards 0". | | conjugate(self) | Conjugate is a no-op for Reals. | | ---------------------------------------------------------------------- | Readonly properties inherited from Real: | | imag | Real numbers have no imaginary component. | | real | Real numbers are their real component. | | ---------------------------------------------------------------------- | Methods inherited from Complex: | | __abs__(self) | Returns the Real distance from 0. Called for abs(self). | | __add__(self, other) | self + other | | __bool__(self) | True if self != 0. Called for bool(self). | | __eq__(self, other) | self == other | | __mul__(self, other) | self * other | | __neg__(self) | -self | | __pos__(self) | +self | | __pow__(self, exponent) | self**exponent; should promote to float or complex when necessary. | | __radd__(self, other) | other + self | | __rmul__(self, other) | other * self | | __rpow__(self, base) | base ** self | | __rsub__(self, other) | other - self | | __rtruediv__(self, other) | other / self | | __sub__(self, other) | self - other | | __truediv__(self, other) | self / other: Should promote to float when necessary. | | ---------------------------------------------------------------------- | Data and other attributes inherited from Complex: | | __hash__ = None class Real(Complex) | To Complex, Real adds the operations that work on real numbers. | | In short, those are: a conversion to float, trunc(), divmod, | %, <, <=, >, and >=. | | Real also provides defaults for the derived operations. | | Method resolution order: | Real | Complex | Number | builtins.object | | Methods defined here: | | __ceil__(self) | Finds the least Integral >= self. | | __complex__(self) | complex(self) == complex(float(self), 0) | | __divmod__(self, other) | divmod(self, other): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __float__(self) | Any Real can be converted to a native float object. | | Called for float(self). | | __floor__(self) | Finds the greatest Integral <= self. | | __floordiv__(self, other) | self // other: The floor() of self/other. | | __le__(self, other) | self <= other | | __lt__(self, other) | self < other | | < on Reals defines a total ordering, except perhaps for NaN. | | __mod__(self, other) | self % other | | __rdivmod__(self, other) | divmod(other, self): The pair (self // other, self % other). | | Sometimes this can be computed faster than the pair of | operations. | | __rfloordiv__(self, other) | other // self: The floor() of other/self. | | __rmod__(self, other) | other % self | | __round__(self, ndigits=None) | Rounds self to ndigits decimal places, defaulting to 0. | | If ndigits is omitted or None, returns an Integral, otherwise | returns a Real. Rounds half toward even. | | __trunc__(self) | trunc(self): Truncates self to an Integral. | | Returns an Integral i such that: | * i>0 iff self>0; | * abs(i) <= abs(self); | * for any Integral j satisfying the first two conditions, | abs(i) >= abs(j) [i.e. i has "maximal" abs among those]. | i.e. "truncate towards 0". | | conjugate(self) | Conjugate is a no-op for Reals. | | ---------------------------------------------------------------------- | Readonly properties defined here: | | imag | Real numbers have no imaginary component. | | real | Real numbers are their real component. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | __abstractmethods__ = frozenset({'__abs__', '__add__', '__ceil__', '__... | | ---------------------------------------------------------------------- | Methods inherited from Complex: | | __abs__(self) | Returns the Real distance from 0. Called for abs(self). | | __add__(self, other) | self + other | | __bool__(self) | True if self != 0. Called for bool(self). | | __eq__(self, other) | self == other | | __mul__(self, other) | self * other | | __neg__(self) | -self | | __pos__(self) | +self | | __pow__(self, exponent) | self**exponent; should promote to float or complex when necessary. | | __radd__(self, other) | other + self | | __rmul__(self, other) | other * self | | __rpow__(self, base) | base ** self | | __rsub__(self, other) | other - self | | __rtruediv__(self, other) | other / self | | __sub__(self, other) | self - other | | __truediv__(self, other) | self / other: Should promote to float when necessary. | | ---------------------------------------------------------------------- | Data and other attributes inherited from Complex: | | __hash__ = None DATA __all__ = ['Number', 'Complex', 'Real', 'Rational', 'Integral'] FILE /usr/lib/python3.10/numbers.py
Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:14 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)