Tech

Arithmetic Operators Notes

Arithmetic Operators Notes

Operator ExampleDescription
M + NAddition of M and N
M – NSubtraction of N from M
M * NMultiplication of M and N
M / NDivision of M by N (The result will be a real number.)
M // NInteger division of M by N (The result will be an integer.)
M % NModulo: find the remainder of M divided by N
M ** NExponentiation: M to the power of N (e.g., 2 ** 4 results in 16. 2*2*2*2=16
Arithmetic Operators

Note: Python also has the math module that contains common math functions (such as sin, cos, etc.)

Shortcut Operators

Operator ExampleDescription
M += NM = M + N
M -= NM = M – N
M *= NM = M * N
M /= NM = M / N
M //= NM = M // N
M %= NM = M % N
Shortcut Operators

Boolean (or Logical) Operators

Operator ExampleDescriptionEffect
A and BAND‘True’ if ‘A’, ‘B’ are both ‘True’; ‘False’ otherwise.
A or BOR‘True’ if either or both of A, ‘B’ are ‘True’. False if both A and B are false.
A == BEqualityTrue if ‘A’ is equal to ‘B’.
A != BInequalityTrue if A is NOT equal to B.
NOT BNegationTrue if B is NOT True.
Boolean (or Logical) Operators