How Python Runs

This course runs your code with CPython 3.12. CPython is the standard Python that you download from python.org. People often say Python is an interpreted language. CPython is the program that does the interpreting. It reads your code and runs it.

Before CPython runs a file, it reads your source code and turns it into bytecode. This step is called compiling. Bytecode is a short list of simple instructions. Then a part of CPython called the virtual machine carries out those instructions one by one.

main.py
   |
   | parse and compile
   v
bytecode
   |
   | execute
   v
CPython virtual machine

The compiling step happens automatically. When you import a module, Python may save its bytecode in a folder named __pycache__, so later runs can skip some work. You don't need to manage this folder. Python can always make it again.

Python checks names and types only when the program reaches them while it runs. So a mistake inside a function that is never called stays hidden:

def later():
    return missing_name

print("program finished")

Output:

program finished

missing_name does not exist. But nothing called later, so Python never noticed the problem. This is one reason to run every part of your code. It is also why the next lesson suggests writing tests.

In the question, pick what the source code, the bytecode and CPython each do.