💾 Archived View for tris.fyi › pydoc › numbers captured on 2023-01-29 at 03:25:03. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-07-16)

🚧 View Differences

-=-=-=-=-=-=-

Back to module index

Go to module by name

numbers

Abstract Base Classes (ABCs) for numbers, according to PEP 3141.

TODO: Fill out more detailed documentation on the operators.

Classes

ABCMeta

Metaclass for defining Abstract Base Classes (ABCs).

        Use this metaclass to create an ABC.  An ABC can be subclassed
        directly, and then acts as a mix-in class.  You can also register
        unrelated concrete classes (even built-in classes) and unrelated
        ABCs as 'virtual subclasses' -- these and their descendants will
        be considered subclasses of the registering ABC by the built-in
        issubclass() function, but the registering ABC won't show up in
        their MRO (Method Resolution Order) nor will method
        implementations defined by the registering ABC be callable (not
        even via super()).
        
mro(self, /)

  Return a type's method resolution order.
register(cls, subclass)

  Register a virtual subclass of an ABC.

              Returns the subclass, to allow usage as a class decorator.
            

Complex

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.
    
conjugate(self)

  (x+y*i).conjugate() returns (x-y*i).
imag = <property object at 0x7f75e13943b0>
  Retrieve the imaginary component of this number.

          This should subclass Real.
        
real = <property object at 0x7f75e1394360>
  Retrieve the real component of this number.

          This should subclass Real.
        

Integral

Integral adds methods that work on integral numbers.

    In short, these are conversion to int, pow with modulus, and the
    bit-string operations.
    
conjugate(self)

  Conjugate is a no-op for Reals.
denominator = <property object at 0x7f75e1394a90>
  Integers have a denominator of 1.
imag = <property object at 0x7f75e1394680>
  Real numbers have no imaginary component.
numerator = <property object at 0x7f75e1394a40>
  Integers are their own numerators.
real = <property object at 0x7f75e1394630>
  Real numbers are their real component.

Number

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).
    

Rational

.numerator and .denominator should be in lowest terms.
conjugate(self)

  Conjugate is a no-op for Reals.
denominator = <property object at 0x7f75e1394950>
imag = <property object at 0x7f75e1394680>
  Real numbers have no imaginary component.
numerator = <property object at 0x7f75e1394900>
real = <property object at 0x7f75e1394630>
  Real numbers are their real component.

Real

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.
    
conjugate(self)

  Conjugate is a no-op for Reals.
imag = <property object at 0x7f75e1394680>
  Real numbers have no imaginary component.
real = <property object at 0x7f75e1394630>
  Real numbers are their real component.

Functions

abstractmethod

abstractmethod(funcobj)

  A decorator indicating abstract methods.

      Requires that the metaclass is ABCMeta or derived from it.  A
      class that has a metaclass derived from ABCMeta cannot be
      instantiated unless all of its abstract methods are overridden.
      The abstract methods can be called using any of the normal
      'super' call mechanisms.  abstractmethod() may be used to declare
      abstract methods for properties and descriptors.

      Usage:

          class C(metaclass=ABCMeta):
              @abstractmethod
              def my_abstract_method(self, ...):
                  ...