Python Numbers — int, float, complex & Math Operations

🐍 Python 3 🟢 Lesson 7 of 12 📂 Phase 1: Python Basics 📅 2026 Edition
Master integer, floating-point, complex number types, floor division, modulus, exponentiation, precision quirks, and math module functions.
1The Three Core Numeric Types in Python
  • int (Integer): Whole numbers without decimal points (e.g. 42, -17, 1_000_000). Python 3 integers have arbitrary precision — they never overflow!
  • float (Floating Point): Numbers with decimal fractions (e.g. 3.14159, -0.005, 2.5e3). Implemented using IEEE 754 double precision.
  • complex: Numbers with real and imaginary parts (e.g. 3 + 4j).
2Arithmetic Operators Overview
┌──────────┬────────────────────────┬─────────────┐ │ Operator │ Description │ Example │ ├──────────┼────────────────────────┼─────────────┤ │ + │ Addition │ 10 + 3 = 13 │ │ - │ Subtraction │ 10 - 3 = 7 │ │ * │ Multiplication │ 10 * 3 = 30 │ │ / │ True Division (float) │ 10 / 3 = 3.333│ │ // │ Floor Division (int) │ 10 // 3 = 3 │ │ % │ Modulus (Remainder) │ 10 % 3 = 1 │ │ ** │ Exponentiation (Power) │ 10 ** 3 = 1000│ └──────────┴────────────────────────┴─────────────┘
3Useful Built-in Math Functions & math Module

Python provides built-in abs(), round(), min(), max(), pow(), plus the standard math library (e.g., math.sqrt(), math.ceil(), math.floor(), math.sin(), math.log()).

💻 Complete Executable Code Example
import math

# Arbitrary precision integers (no integer overflow in Python!)
huge_num = 2 ** 100
print(f"2 ** 100 = {huge_num}")

# Floating point arithmetic & floor division
total = 25
people = 4
print(f"True Division (/):  {total} / {people} = {total / people}")
print(f"Floor Division (//): {total} // {people} = {total // people}")
print(f"Modulus Remainder (%): {total} % {people} = {total % people}")

# Advanced math module helpers
radius = 7.5
area = math.pi * (radius ** 2)
print(f"
Circle Area (r={radius}): {area:.2f}")
print(f"Square Root of 144: {math.sqrt(144)}")
print(f"Ceiling of 4.2: {math.ceil(4.2)}, Floor of 4.8: {math.floor(4.8)}")
⚠️ Common Pitfall: Floating Point Representation Quirks

In Python (and all languages using IEEE 754), 0.1 + 0.2 evaluates to 0.30000000000000004 due to binary fraction rounding. For financial precision calculations, use Python’s decimal.Decimal module.

💻 Try It Yourself — Hands-on Practice Challenge

Calculate investment compound interest using exponentiation operator (**).

principal = 10000  # $10,000 initial
annual_rate = 0.08 # 8% annual return
years = 5

future_value = principal * ((1 + annual_rate) ** years)
profit = future_value - principal

print(f"💵 Initial Investment: ${principal:,}")
print(f"📈 Value after {years} years: ${future_value:,.2f}")
print(f"💰 Total Profit Earned: ${profit:,.2f}")
Run This Code in Our Online Compiler →
Frequently Asked Questions (FAQ)

Q: How large can an integer be in Python?

In Python 3, integers have unlimited precision constrained only by available system RAM memory.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy & tested on Python 3.12+ runtime · Last updated August 2026