Is Python a compiled language or an interpreted language?

Hi, I need to know is python a compiled language or an interpreted language

1 Like

Hi Jhon,

As per my understanding, for the most part, Python is an interpreted language and not a compiled one, although compilation is a step. Python code, written in .py file is first compiled to what is called bytecode, which is stored with a .pyc or .pyo format.

For example, when you write a program in C/C++, you have to compile it. Compilation involves translating your human understandable code to machine understandable code, or Machine Code. Machine code is the base level form of instructions that can be directly executed by the CPU. Upon successful compilation, your code generates an executable file. Executing this file runs the operations in your code step by step.

Instead of translating source code to machine code like C++, Python code is translated to bytecode. This bytecode is a low-level set of instructions that can be executed by an interpreter. In most PCs, Python interpreter is installed at /usr/local/bin/python3.8. Instead of executing the instructions on CPU, bytecode instructions are executed on a Virtual Machine.

Hope I answered your question. :slight_smile:

2 Likes

Hey Jhon,

Defintiely Python is an interpreted language. It means that Python interprets and executes each statement that you write in it, unlike the Compiled languages, in which the whole program is compiled and executed at once.

For example, in Java, you have to write the complete code and execute it. The Java compiler will compile the complete code at once and point out errors, if any.

But in Python, it does not wait for the whole code. Each statement that you write is interpreted.