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.
| Operator | Method |
|---|---|
~ | __invert__ |
- | __neg__ |
+ | __pos__ |