9 min read Beginner Lesson 4 of 11
Part 2 — Building with Functions

Functions & Decomposition

A 10,000-line monolithic script is impossible to debug or scale. Functions enable Functional Decomposition — breaking complex engineering problems into small, isolated, reusable, and testable units.

The Black Box Mental Model

A function is a magical black box. You feed in inputs (arguments), it performs internal transformations in its own private stack frame, and it ejects a single output (return value) without polluting the outside global scope.

Anatomy of a Clean Python Function

def calculate_tax(subtotal: float, rate: float = 0.08) -> float:
"""Calculate total tax amount given subtotal and rate."""
tax_amount = subtotal * rate
return round(tax_amount, 2)

Quick Summary

  • Functions encapsulate isolated logic with clear inputs and return values.
  • Next, we explore Python's built-in Data Structures (Lists, Dicts, Sets, Tuples).