Python Subtraction

Python subtraction is done with -, the subtraction operator:

>>> 8 - 3
5
>>> 8 - 2 - 2
4

Subtracting floats:

>>> 11.5 - 8.3
3.1999999999999993

Note that floating point operations can produce tiny rounding errors, 11.5 – 8.3 is not necessarily 3.2.

If any of the numbers in the operation are floats, Python will return a float.

Subtracting negatives:

>>> -8 - -11
3

Just adding a - in front of a constant/variable will just change the sign of the value:

>>> -(3)
-3
>>> -(-3)
3