The Building Blocks of Python from the Ground Up

The Building Blocks of Python from the Ground Up
Photo by Susan Holt Simpson / Unsplash

TL;DR: I've been working with Python for three years now. It took a deep dive into stacks, heaps, python.exe, and bytecode to finally get the internal structure of every script I write.

Under the hood, Python does its work using stacks built in RAM. python.exe creates the call stack and builds one stack frame for each active function. Within each frame, it sets up two internal stacks — the value stack, where expressions are evaluated and temporary results are stored, and the block stack, which tracks control flow structures like loops and exception blocks. I like to think of the value stack as Jimmy Page and the block stack as John Paul Bonham.

Learning how Python actually runs helped me understand Python code more clearly. At its core, a Python script is made of:

  • Functions — code blocks that do work and return results. They are Python's lingua franca.
  • Identifiers — names that refer to values, functions, or other objects in memory.
  • Values — the actual data. They can be scalar (like numbers or strings) or structured (like lists, dictionaries, or tuples).
  • Flow controllers — keywords that direct the execution path of the Python virtual machine, like if statements, loops, try...except, break, and continue.

That’s the foundation.
Everything else in Python builds on these.

Sources & Links

Read more