Is Python interpreted or compiled, and why does the answer matter in practice?
Answer
CPython compiles source into platform-independent bytecode (cached as .pyc files), and CPython's interpreter then executes that bytecode instruction by instruction — not "line by line" in the source-code sense, since one line of source can expand into many bytecode instructions. It is neither purely interpreted nor compiled to native machine code the way C is. In practice this means Python catches many syntax errors early at compile time, but most name and type errors only surface at runtime because nothing checks them ahead of time.
Strong answer includes
- source to bytecode to interpreter
- .pyc bytecode cache
- interpreter executes bytecode instructions, not source lines
Practical example
Running
python app.pyfirst compiles app.py to bytecode in __pycache__/app.cpython-314.pyc, then the interpreter executes that bytecode; a typo in a rarely-called function only fails when that code path runs.