Arithmetic Operations

Arithmetic operations

Python gives you the arithmetic you already know from math class, plus two operators that are new: floor division and modulus. This table is the whole set.
OperatorNameDescription
a + bAdditionSum of a and b
a - bSubtractionDifference of a and b
a * bMultiplicationProduct of a and b
a / bTrue divisionQuotient of a and b
a // bFloor divisionQuotient of a and b, removing fractional parts
a % bModulusRemainder after division of a by b
a ** bExponentiationa raised to the power of b
-aNegationThe negative of a
+aUnary plusa unchanged (rarely used)
This set covers addition through floor division. Modulus gets a set of its own next, and exponentiation and negation come after that.

Mixing types

An expression on two floats produces a float.
When an expression's operands are an int and a float, Python automatically converts the int to a float.

True division vs floor division

The operator / is true division and the operator // returns floor division, which rounds down after the true divide. True divide / always gives the answer as a float.