Skip to main content
Mentr by PaprlybyPaprly
Student Guides

Is Python Compiled or Interpreted? A Clear Answer

Python is both: CPython compiles your code to bytecode, then interprets it. What that means, why “online Python compiler” is still the right search, and how to see bytecode yourself.

Mentr Engineering6 min read

It's one of the most common Python interview and exam questions, and the honest answer is “both”. The standard Python, CPython, first compiles your code to bytecode and then interprets that bytecode. Here's what that means in plain terms, and how to see it for yourself.

The short answer

  1. Compile: CPython reads your .py source and compiles it into bytecode, a compact set of instructions for a virtual machine.
  2. Interpret: CPython's interpreter loop runs those bytecode instructions one by one.

So Python is usually called an interpreted language, because there is no separate step that turns your program into a machine-code .exe. Under the hood there is still a compiler; it just runs automatically every time.

See the bytecode yourself

Python ships with the dis module, which shows the bytecode for any function. Paste this into an online Python compiler and press Run:

import dis

def add(a, b):
    return a + b

dis.dis(add)

You'll see instructions such as LOAD_FAST and RETURN_VALUE: that's what the interpreter actually executes. When you import a module, CPython also caches its bytecode in a __pycache__ folder as .pyc files so it doesn't recompile it next time.

Compiled vs interpreted, side by side

C vs Python (CPython)
C (typical)Python (CPython)
Output of compilingMachine code for one CPUBytecode for the Python virtual machine
When it compilesOnce, before you runAutomatically, each time (with .pyc caching)
What runs itThe CPU directlyCPython's interpreter loop
PortabilityRebuild per platformSame source runs anywhere Python runs

Other implementations differ: PyPy adds a just-in-time (JIT) compiler that turns hot code into machine code, and recent CPython versions include an experimental JIT that is off by default.

So why is it called an “online Python compiler”?

Because that's what people search for. Technically, an online Python compiler is an online Python interpreter. Mentr's runs the standard CPython 3.14 interpreter, itself compiled to WebAssembly so it can run inside your browser. That's a neat twist: a C program (CPython) compiled to WebAssembly, interpreting bytecode compiled from your Python.

Common questions

Is Python a compiled or an interpreted language?
Both. CPython compiles source code to bytecode, then interprets the bytecode. It is usually called interpreted because there is no separate build step that produces machine code.
What is a .pyc file?
A cached bytecode file. When a module is imported, CPython saves its compiled bytecode in __pycache__ so later imports skip recompiling.
Does Python have a JIT compiler?
PyPy does. Recent CPython versions also include an experimental JIT, which is off by default.