Fundamentals 17 min read

Is Python a Compiled or Interpreted Language? Uncover the Truth

This article explores whether Python is a compiled or interpreted language by examining its compilation stages, error‑message generation, differences across Python versions, and the broader distinction between static and dynamic language features, ultimately showing that Python combines both compilation and interpretation.

21CTO
21CTO
21CTO
Is Python a Compiled or Interpreted Language? Uncover the Truth

Many people assume Python is purely interpreted, but it actually undergoes compilation steps before execution.

Technical Background

The author is creating a course on reading error messages for C, Python, and Java, noting that errors appear at different stages: some are reported during compilation, others at runtime.

Compilation Stages in C

Preprocessing

Lexical analysis

Syntax analysis

Semantic analysis

Linking

Python lacks preprocessing and linking stages, so those topics are omitted.

Python Error Message Game

A small program with multiple errors is used to see which error is reported first in Python 3.12.

1 / 0
print() = None
if False
    ñ = "hello

The first error reported is the syntax error on the last line (unterminated string), showing that Python scans the whole file before execution.

Subsequent Rounds

After fixing the first error, the next reported error is the assignment to a function call:

File "/private/tmp/round_2.py", line 2
  print() = None
  ^^^^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?

Further rounds demonstrate that syntax errors are detected before runtime errors like ZeroDivisionError.

Python Virtual Machine

Python source is compiled to bytecode, which the Python Virtual Machine (PVM) executes, making Python a “compiled‑interpreted” language.

Older Python versions had an extra stage checking valid assignment targets, causing differences in error order between Python 3.8 and Python 3.12.

Broader Perspective

The article argues that the compile vs interpret dichotomy is misleading; languages have static and dynamic properties, and Python leans toward dynamic features.

It also notes that many “interpreted” languages like JavaScript are JIT‑compiled, and that REPLs exist for compiled languages such as Java (jshell) and Haskell (GHC).

Conclusion: Whether Python is compiled or interpreted is less important than understanding which properties are determined statically versus dynamically.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonCompilationError HandlingInterpretation
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.