Next / Previous / Contents / TCC Help System / NM Tech homepage

26.3.3. Unary operator special methods

You can define these special methods in your class to specify what happens when a unary operator such as “-” (negate) is applied to an instance of the class.

In each case, the definition will look like this:

    def __method__(self):
        ...

The method returns the result of the operation.

OperatorMethod
~__invert__
-__neg__
+__pos__