Introduction
Python is a popular programming language used by developers worldwide. It is known for its simplicity, readability & versatility. Python code is executed line by line, which makes it an interpreted language.

In this article, we will understand what it means for Python to be interpreted, the advantages & disadvantages of interpreted languages, and how Python's interpretation process works under the hood.
Python is Both Compiled as well as Interpreted
When you write Python code & run it, the code is first compiled into bytecode. This bytecode is then interpreted by the Python virtual machine (PVM) to execute the program. The compilation step is done automatically & transparently in the background.
The Python compiler reads the source code, checks for syntax errors, & generates bytecode instructions. These bytecode instructions are lower-level & more compact than the original source code. They are stored in .pyc files, which are binary files containing the bytecode.
Once the bytecode is generated, the Python interpreter takes over. It reads the bytecode instructions one by one & executes them. The interpreter translates each bytecode instruction into corresponding machine code that the computer's processor can understand & run.
This combination of compilation & interpretation allows Python to provide the benefits of both approaches. The compilation step helps catch syntax errors early & generates optimized bytecode, while the interpretation step allows for flexibility & ease of use.
Here's a simple example to illustrate the process:
# Python source code
print("Hello, World!")
When you run this code, the following steps occur:
-
The Python compiler compiles the source code into bytecode.
-
The bytecode is loaded into the Python virtual machine.
-
The Python interpreter executes the bytecode, which prints "Hello, World!" to the console.
So, while Python is primarily known as an interpreted language, it actually involves a compilation step before interpretation. This hybrid approach contributes to Python's popularity & success as a programming language.