Is Python interpreted, compiled or both?

Let us first see is short what is ‘compile’ and ‘interpreted’ means.

In the simple definition ‘compile‘ means to convert a high-level language program into a binary executable machine code (CPU instructions). The result of ‘compile’ is a file which can be executed directly.

In the simple definition, ‘interpreted‘ means reading the source code one line at a time, and executing it.

In Python, the source code is compiled into bytecode. This bytecode is similar to CPU instructions, but instead of being executed by the CPU, they are executed by software called a virtual machine (or Python Virtual Machine).

The point to note in case of Python is that this conversion of source code to bytecode is implicit and in Python you need not to invoke compiler explicitly. Since you never invoke a compiler while running a Python file, Python is said to be interpreted. When you run a Python file, the Python implementation compiles the file into bytecode and this is hidden from the programmer.

We can also understand this to understand in comparison to other compiled languages like Java. To run a Java program you have to explicitly compile a Java file. The result of compiling a Java file is also a bytecode. But in Java you have to invoke a compiler explicitly. This is not the case with Python. That is why Java is said to be ‘compiled’ and Python is said to be ‘interpreted’.