Practice With Arithmetic Operators

Practice these programming examples to internalize these concepts.

4. Unary Arithmetic Operations

A unary mathematical expression consists of only one component or element, and in Python the plus and minus signs can be used as a single element paired with a value to return the value's identity (+), or change the sign of the value (-).

Though not commonly used, the plus sign indicates the identity of the value. We can use the plus sign with positive values:

i = 3.3
print(+i)


Output:

3.3

When we use the plus sign with a negative value, it will also return the identity of that value, and in this case it would be a negative value:

j = -19
print(+j)


Output:

-19

With a negative value, the plus sign returns the same negative value.

The minus sign, alternatively, changes the sign of a value. So, when we pass a positive value we'll find that the minus sign before the value will return a negative value:

i = 3.3
print(-i)


Output:

-3.3

Alternatively, when we use the minus sign unary operator with a negative value, a positive value will be returned:

j = -19
print(-j)


Output:

19

The unary arithmetic operations indicated by the plus sign and minus sign will return either the value's identity in the case of +i, or the opposite sign of the value as in -i.