DEV Community

Cover image for Is Python a compiled language?
icncsx
icncsx

Posted on

Is Python a compiled language?

Is Java a compiled language?

If you think yes, then Python is also a compiled language.

In Python, the source code is compiled into bytecode. If you've worked with Java before, then the term bytecode should sound familiar to you; bytecode is what the JVM interprets to machine code. In Python, there is also a virtual machine. It's simply called the Python Virtual Machine (PVM). Here is a graphic of CPython's implementation of the Python programming language.

Alt Text

So why do we have this preconceived notion that Python isn't a compiled language? Perhaps it's the implicit compilation step.

When working with a Python program, you never invoke a compiler; you simply run python main.py. This is different than Java, for example, where you have to explicitly run the Java compile step. For this reason, Java is often called a compiled language. But Python also compiles to bytecode. Both languages execute the bytecode with a software implementation of a virtual machine.

Top comments (3)

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

These days almost all "interpreted" languages are compiled. The main difference seems to be more about when the compilation happens, which with "interpreted" languages is usually once the code is loaded, whereas "compiled" languages are compiled manually ahead of time and usually stored and distributed in compiled form.

There's also the question of what it gets compiled to. C compiles to native machine code, Java compiles to VM bytecode. In a way that makes java less compiled than C, but still more compiled than python. Python is more interpreted than C, but not as interpreted as bash (which doesn't use a VM at all)

Collapse
 
dynamicsquid profile image
DynamicSquid

Don't some version of Java compilers actually compile the bytecode too, giving Java its compiled name?

Collapse
 
icncsx profile image
icncsx

Yes. I believe the GNU compiler for Java can compile Java to machine code. On that note, Python also has a JIT compiler called PyPy which generates machine code at runtime.