Episode 3 of 29
Numbers in Python
Learn about integers, floats, and arithmetic operations in Python.
Python handles numbers intuitively. Let us explore number types and operations.
Number Types
- Integers (int) — Whole numbers: 5, -3, 100
- Floats (float) — Decimal numbers: 3.14, -0.5
Arithmetic Operators
print(5 + 3) # Addition: 8
print(10 - 4) # Subtraction: 6
print(3 * 7) # Multiplication: 21
print(15 / 4) # Division: 3.75
print(15 // 4) # Floor division: 3
print(15 % 4) # Modulus: 3
print(2 ** 4) # Exponent: 16Type Conversion
x = int(3.9) # 3
y = float(5) # 5.0
z = str(100) # "100"Useful Functions
print(abs(-7)) # 7
print(round(3.7)) # 4
print(max(3, 7, 1)) # 7