Is Python a compiled language or interpreted language?
(From post by Amit Khomane)
How Your Python Code Gets Executed
The Python code we write is source code, with extension .py. The Python compiler translates source code into target code, which is Python bytecode with extension .pyc (generated in the pycache subdirectory).
What’s Compilation?
Compilation takes a high-level language source code and transforms it into low-level language target code, usually assembly code or machine code. The purpose of compilation is to obtain code that can be executed by the machine processor (or a virtual machine) for which was written.
There are also situations in which the target code of compilation is some kind of intermediate code, such as bytecode:
- Java compiler produces Java bytecode
- Python compiler CPython produces Python bytecode
- There are also other Python compilers, such as Jython, that produce Java bytecode
How Python Code Executes
CPython compiler compiles a .py program into bytecode .pyc. Python Virtual Machine (PVM) executes the instructions in the bytecode to produce the program’s output.
Python Virtal Machine is an interpreter - a program that makes use of the host machine architecture through its operating system and operating system programming libraries.