🐍 Lesson 7: Python Numbers
1. What are numbers?
Short answer → Python mainly represents numbers using three data types.
In other words → In Python, numbers are mainly represented by three data types.
2. Number Types
- int (Integer) → whole numbers (e.g.
10,-5,1000) - float (Floating point) → decimal numbers (e.g.
3.14,-0.5) - complex → complex numbers (e.g.
2 + 3j)
3. Arithmetic Operators
Python uses the following operators for doing math with numbers.
| Operator | အဓိပ္ပာယ် | ဥပမာ | Result |
|---|---|---|---|
| + | ပေါင်း | 5 + 3 | 8 |
| - | နုတ် | 5 - 3 | 2 |
| * | မကြိမ် | 5 * 3 | 15 |
| / | Division (ဒဿမနဲ့) | 5 / 2 | 2.5 |
| // | Floor Division (အနိမ့်ဆုံးကိန်းပြည့်) | 5 // 2 | 2 |
| % | Modulus (ကျန်ရှိ) | 5 % 2 | 1 |
| ** | Exponentiation (အနိပ်) | 2 ** 3 | 8 |
4. Summary
✅ Python Numbers → int, float, complex
✅ Arithmetic operators → + - * / // % **
✅ Use casting and built-in functions to convert and compute with numbers
python
# ===== 1. Number Types =====
x = 10 # int
y = 3.14 # float
z = 2 + 3j # complex
print(f"Int: {x}, Type: {type(x)}")
print(f"Float: {y}, Type: {type(y)}")
print(f"Complex: {z}, Type: {type(z)}")
# ===== 2. Arithmetic Operations =====
a = 7
b = 3
print(f"\n===== Arithmetic Operators =====")
print(f"{a} + {b} = {a + b}") # Addition
print(f"{a} - {b} = {a - b}") # Subtraction
print(f"{a} * {b} = {a * b}") # Multiplication
print(f"{a} / {b} = {a / b}") # Division
print(f"{a} // {b} = {a // b}") # Floor Division
print(f"{a} % {b} = {a % b}") # Modulus
print(f"{a} ** {b} = {a ** b}") # Exponentiation
# ===== 3. Type Conversion =====
print(f"\n===== Type Conversion =====")
num = 5
print(f"int to float: {float(num)}") # 5.0
print(f"float to int: {int(3.99)}") # 3
# ===== 4. Useful Functions =====
print(f"\n===== Useful Functions =====")
print(f"abs(-10) = {abs(-10)}") # Absolute value
print(f"pow(2, 4) = {pow(2, 4)}") # Power
print(f"round(3.14159, 2) = {round(3.14159, 2)}") # RoundingYou should see
Int: 10, Type: Float: 3.14, Type: Complex: (2+3j), Type: ===== Arithmetic Operators ===== 7 + 3 = 10 7 - 3 = 4 7 * 3 = 21 7 / 3 = 2.333... 7 // 3 = 2 7 % 3 = 1 7 ** 3 = 343 ===== Type Conversion ===== int to float: 5.0 float to int: 3 ===== Useful Functions ===== abs(-10) = 10 pow(2, 4) = 16 round(3.14159, 2) = 3.14