Arithmetic Operators Notes
Operator Example | Description |
M + N | Addition of M and N |
M – N | Subtraction of N from M |
M * N | Multiplication of M and N |
M / N | Division of M by N (The result will be a real number.) |
M // N | Integer division of M by N (The result will be an integer.) |
M % N | Modulo: find the remainder of M divided by N |
M ** N | Exponentiation: 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 Example | Description |
M += N | M = M + N |
M -= N | M = M – N |
M *= N | M = M * N |
M /= N | M = M / N |
M //= N | M = M // N |
M %= N | M = M % N |
Shortcut Operators
Boolean (or Logical) Operators
Operator Example | Description | Effect |
A and B | AND | ‘True’ if ‘A’, ‘B’ are both ‘True’; ‘False’ otherwise. |
A or B | OR | ‘True’ if either or both of A, ‘B’ are ‘True’. False if both A and B are false. |
A == B | Equality | True if ‘A’ is equal to ‘B’. |
A != B | Inequality | True if A is NOT equal to B. |
NOT B | Negation | True if B is NOT True. |
Boolean (or Logical) Operators