🔍 Deep Dive: Arithmetic Operators in Python
Arithmetic operators are used to perform mathematical operations between numeric values. Python supports several arithmetic operators that you’ll use regularly.
List of Arithmetic Operators
| Operator | Name | Example | Result |
|---|---|---|---|
+ |
Addition | 3 + 2 |
5 |
- |
Subtraction | 5 - 2 |
3 |
* |
Multiplication | 4 * 2 |
8 |
/ |
Division | 8 / 4 |
2.0 |
// |
Floor Division | 7 // 2 |
3 |
% |
Modulus | 7 % 3 |
1 |
** |
Exponentiation | 2 ** 3 |
8 |
Examples in Python
a = 10
b = 3
print(a + b) # 13
print(a - b) # 7
print(a * b) # 30
print(a / b) # 3.333...
print(a // b) # 3
print(a % b) # 1
print(a ** b) # 1000
Order of Operations (PEMDAS)
Python follows the PEMDAS order for evaluating expressions:
- Parentheses
- Exponents
- Multiplication and Division (from left to right)
- Addition and Subtraction (from left to right)
result = 5 + 2 * 3 # result = 11
result = (5 + 2) * 3 # result = 21