8.11. Operator Numerical

  • -obj - neg

  • +obj - pos

  • ~obj - invert

8.11.1. About

Table 8.9. Numerical Operator Overload

Operator

Method

-obj

obj.__neg__()

+obj

obj.__pos__()

~obj

obj.__invert__()

8.11.2. Operator

  • operator.neg(obj) - neg - -obj

  • operator.pos(obj) - pos - +obj

  • operator.invert(obj) - invert - ~obj

>>> import operator
>>> operator.neg(1)
-1
>>> operator.pos(1)
1
>>> operator.invert(1)
-2