Compiler and interpreter: what is the difference?
Last updated: 2026-11-26
A compiler translates a program from one language into another, often into a lower-level form that can be run later. An interpreter carries out source code and does not turn it into machine code first. To predict when an error shows up, ask which checks happen before the first line runs and which happen while it runs.
Start learning No account needed
1. What each one does
A compiler takes source code and produces output in a target language, such as machine code. Running the program is a separate step. An interpreter takes source code and carries it out. The line between them can blur: an interpreter may first translate the source into an intermediate form called bytecode, and some systems compile that bytecode to machine code while the program runs, which is called just-in-time compilation.
So "compiled language" and "interpreted language" are shortcuts. They describe how a language is usually run. Python's own glossary calls Python interpreted, says the distinction can be blurry, and says Python source is compiled into bytecode.
2. A worked example: three small programs
Predict what each program prints and where it fails, then read the output. A has an extra closing bracket on line 3. B divides by zero on line 3. C uses a name, discount, that was not defined, inside an if whose condition is false. The same script also builds C versions of A and C, and a program D, with the C compiler command cc.
A short script, scripts/compiler-interpreter-worked-example.py, produced this output:
program A
1 price = 8
2 print("price is", price)
3 total = price * 3)
Python, whole file: printed nothing -> SyntaxError, line 3
toy, line at a time: printed price is 8 -> SyntaxError, line 3
program B
1 price = 8
2 print("price is", price)
3 print("share is", price / 0)
Python, whole file: printed price is 8 -> ZeroDivisionError, line 3
toy, line at a time: printed price is 8 -> ZeroDivisionError, line 3
program C
1 price = 8
2 if price > 100:
3 print(discount)
4 print("done")
Python, whole file: printed done -> no error
C version of program A
1 #include <stdio.h>
2 int main(void) {
3 int price = 8;
4 printf("price is %d\n", price);
5 int total = price * 3);
6 return 0;
7 }
cc: error on line 5: extraneous ')' before ';'
no program built, so nothing ran
C version of program C
1 #include <stdio.h>
2 int main(void) {
3 int price = 8;
4 if (price > 100) { printf("%d\n", discount); }
5 puts("done");
6 return 0;
7 }
cc: error on line 4: use of undeclared identifier 'discount'
no program built, so nothing ran
C program D
1 #include <stdio.h>
2 int main(void) {
3 int people;
4 if (scanf("%d", &people) != 1) return 2;
5 if (people == 0) { puts("cannot divide by zero"); return 1; }
6 printf("share is %d\n", 8 / people);
7 return 0;
8 }
cc: compiled with no error
run, typed 2: printed share is 4 (exit status 0)
run, typed 0: printed cannot divide by zero (exit status 1)
| Program | Problem | Python, whole file | When it was found |
|---|---|---|---|
| A | Extra bracket | Prints nothing, SyntaxError on line 3 | Before line 1 ran |
| B | Division by zero | Prints the price, then ZeroDivisionError on line 3 | While line 3 ran |
| C | Undefined name in a skipped branch | Prints done, no error | Not found in this run |
Program A is the surprise if you picture an interpreter reading one line, running it, and moving on. Python compiles source code into bytecode, and for this file the syntax error stopped that step, so no line ran. The "toy, line at a time" row is a small stand-in we wrote that checks each line when it reaches it. It prints the price before it reaches the bad bracket.
3. How a compiler changes the picture
The lower part of the output shows three C programs. A compiler checks the source before it hands you a program to run, so an error it finds at that stage stops you before the first line runs.
| C program | What cc did | What ran |
|---|---|---|
| A, extra bracket | Reported an error on line 5 | Nothing |
| C, undeclared name in a skipped branch | Reported an error on line 4 | Nothing |
| D, divisor typed in | Compiled with no error | With 2 it printed a share; with 0 its own check stopped it |
Compare the two versions of program C. Python ran its file and printed done, while cc rejected the C file although the branch would have been skipped. D compiles because its source has no error, and its divisor does not exist until someone types it during a run. For a statically typed language, a compiler also does type checking. Which checks happen early depends on the language and the tool, so ask about the specific one in your course.
4. A common mistake: "interpreted means no checking up front"
Program A shows why that rule misleads for Python. A more useful habit is to sort an error into one of two groups. Can it be seen from the text of the program, such as a missing bracket? Or does it depend on what happens during the run, such as a value being zero? Then ask which of the first group your tool checks before it starts.
5. Test yourself
Close this page and answer these. If program C's condition were price < 100, what would Python print, and which error would you see? If B's line 3 sat inside the false if, would you see an error? Say why for each, then run the code to check.
For related study advice, see how to learn programming without copying code and how to test yourself.
What the sources found, and their limits
Wikipedia, Compiler and Interpreter (computing). They give the two definitions, the use of bytecode and just-in-time compilation, the blurred boundary, and the type checking and name binding checks in a compiler's front end, including semantic analysis. Sources: Compiler and Interpreter, read in part on 2026-11-25.
Python documentation. The glossary describes Python as interpreted with a bytecode compiler. The tutorial separates syntax errors, found by the parser, from exceptions, found during execution. Sources: Glossary and Errors and exceptions, read in part on 2026-11-25. Limits: the three programs show one Python run. The toy runner is ours and handles single-line statements. The C results come from Apple clang 21, run as cc -std=c11; another compiler may word its messages differently.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start. It's an AI tutor, free to try.
Bring a program whose error shows up at a time you did not expect. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller, so you work it out yourself. You must be 18 or older, and guest conversations are deleted 7 days after the last activity.
FAQ
Is Python compiled or interpreted? The Python glossary calls it interpreted and says the distinction can be blurry, because Python source is compiled into bytecode.
Does a program that compiles run without errors? No. Some errors depend on what happens during the run, such as the values a user enters.
Start with what you're working on
Tell the tutor which error you are trying to predict and let it ask you the questions.
Start learning No account needed
See also: all study guides