Next: Binary arithmetic operations Up: Expressions and conditions Previous: Calls

Unary arithmetic operations

All unary arithmetic (and bit-wise) operations have the same priority:


u_expr:         primary | "-" u_expr | "+" u_expr | "~" u_expr

The unary "-" (minus) operator yields the negation of its numeric argument.

The unary "+" (plus) operator yields its numeric argument unchanged.

The unary "~" (invert) operator yields the bit-wise inversion of its plain or long integer argument. The bit-wise inversion of x is defined as -(x+1).

In all three cases, if the argument does not have the proper type, a TypeError exception is raised.


guido@cwi.nl