Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Python
Stage 5: Specialization

Part 01 / Topic 5 of 7

How the interpreter works

An interpreter is a program that reads your code and runs it. When you run python hello.py, three steps happen:

hello.py  ──compile──▶  bytecode  ──run──▶  PVM (Python Virtual Machine)
(source)               (.pyc)              (runs the instructions)
  1. Compile: Python turns your source code into bytecode (simple instructions, not machine code).
  2. Cache: For imported modules, bytecode is saved as .pyc files inside a __pycache__ folder. Next time, Python skips compiling if the file has not changed.
  3. Run: The PVM reads the bytecode and does the work.

The standard Python you download is called CPython (written in C).

Real-world example: Peek at the bytecode of a tiny function with the dis module. (import loads a module, Part 7; def makes a function, Part 5. Just read along for now.)

import dis

def add(a, b):
    return a + b

dis.dis(add)
# Output (Python 3.13, may look a little different in other versions):
#   3 RESUME 0
#
#   4 LOAD_FAST_LOAD_FAST 1 (a, b)
#               BINARY_OP 0 (+)
#               RETURN_VALUE
import importlib.util

# Where would Python cache the bytecode for a module named shop.py?
print(importlib.util.cache_from_source("shop.py"))
# __pycache__/shop.cpython-313.pyc (the number matches your version: -314 on 3.14)
Word Meaning
Source code The .py file you write
Bytecode Low-level instructions made from your code
.pyc A file that stores bytecode
__pycache__ Folder where .pyc files are kept
PVM The engine that runs bytecode
CPython The main Python implementation

You never need to edit .pyc files. It is safe to delete __pycache__; Python makes it again.

🔍 Going deeper: Bytecode is a CPython detail. It changes between versions, so a .pyc from 3.12 is not used by 3.13 (that is why the file name has cpython-313). Your main script is compiled fresh each run; only imported modules are cached. The dis output above also changes between versions (3.12 shows two LOAD_FAST lines instead of one LOAD_FAST_LOAD_FAST). 3.13 added two experimental extras. They are separate builds, not switches in the normal Python: a "free-threaded" build without the GIL (the lock that lets only one thread run Python code at a time), installed as python3.13t, and a JIT compiler (turns hot bytecode into machine code), added when Python is built with --enable-experimental-jit and still off by default. In 3.14 the free-threaded build is officially supported (PEP 779), but it is still not the default.

🧪 Quick quiz — answer from memory, then check.

  1. What are the three steps when you run python hello.py?
  2. Is it safe to delete the __pycache__ folder?
  3. What is CPython?
Show the answers
  1. Compile the source to bytecode, cache imported modules' bytecode as .pyc files, and the PVM runs the bytecode.
  2. Yes — Python simply makes it again.
  3. The standard Python implementation (the one you download), written in C.

Done here? The practice set for Part 1 — 6 exercises with solutions — is on the part page.

Search the guide