Integers (int)
Integers are whole numbers, positive or negative, without a decimal point (e.g., 10, -500, 0).
python population = 1000000 year = 2024 neg_num = -50
Basic Arithmetic Operators
| Operator | Operation | Example |
|---|---|---|
+ | Addition | 5 + 3 -> 8 |
- | Subtraction | 10 - 4 -> 6 |
* | Multiplication | 6 * 7 -> 42 |
/ | Division | 10 / 3 -> 3.333... (Always returns a float) |
// | Floor Division | 10 // 3 -> 3 (Discards the remainder) |
% | Modulo (Remainder) | 10 % 3 -> 1 |
** | Exponentiation | 2 ** 3 -> 8 (2 cubed) |
Operator Precedence
Python follows standard mathematical order of operations (PEMDAS/BODMAS):
- Parentheses
() - Exponents
** - Multiplication
*, Division/, Floor Division//, Modulo%(from left to right) - Addition
+, Subtraction-(from left to right)
python result = 5 + 2 * (10 / 5) ** 2
5 + 2 * (2.0) ** 2
5 + 2 * 4.0
5 + 8.0
13.0
print(result)