Translators: Compilers, Interpreters and Assemblers
You cannot write Python and hand it to a CPU. Something has to translate it. That something is a translator - and the type you use changes how your program is distributed, debugged, and how fast it runs.
A CPU executes binary machine code instructions. Full stop. It does not know what Python is. It does not know what Java is. It only knows operations like "load this value", "add these registers", "jump to this memory address".
So when you press Run in Python, what happens? A piece of software called a translator steps in. It reads your Python code and either converts it to machine code all at once (compiler) or executes it line by line as it translates (interpreter). The CPU never actually runs Python - it runs the machine code that the translator produces.
Translates whole program first, then runs.
Translates and runs one line at a time.
Compilation is not one operation - it is a pipeline of stages. Click each stage to see what it does to your code.
Tokens: [IDENTIFIER:x] [OPERATOR:=] [NUMBER:5] [OPERATOR:+] [IDENTIFIER:y]
Type a line of code and watch the lexer break it into tokens in real time. Each token type is colour-coded.
The compiler reads the entire program first, checks all of it, then runs the output in one go. The interpreter translates and executes one line at a time. Try adding a bug to line 3 to see the most important exam difference.
This is one of the most common exam topics. Be ready to state three differences between a compiler and an interpreter, with reasons. Key points: (1) compiler translates whole program first vs interpreter line by line; (2) compiled code runs faster as no translation overhead at runtime; (3) interpreter stops at first error making debugging easier; (4) compiled produces standalone executable, interpreter requires the interpreter software to be installed; (5) source code is hidden after compilation, visible with an interpreter.
Python is described as an interpreted language, but modern Python uses a hybrid approach: it first compiles your code to bytecode (.pyc files), then the Python interpreter runs that bytecode. Why might this be faster than pure interpretation? And why is it still not as fast as compiled languages like C?