Internal Working of Python

Python is an Object Oriented language and interpreted language . Lets see the internal working of Python i.e. how the python code is running behind the scene .

Compiled Vs Interpreted

A compiled language is a language in which the whole code is converted in machine code at once . Example - C++ . Compiled language provides fast output but increases chances of error in the code .

In Interpreted language the code is converted into machine code line by line . Example - Python . Interpreted language is comparatively slower than compiled language due to line by line interpretation but it decreases the chances of error and reduces redundancy .

Internal Working

  • This python code/script is firstly converted into Bytecode(.pyc or cpython) afterwards this Bytecode is converted to machine code with PVM(Python Virtual Machine).

  • Bytecode(.pyc) - Bytecode is the low level interpretation of the program or script you entered . This Bytecode is not machine code (Code that gives direct commands to the hardware). Bytecode is platform independent, which means it can run on any platform with compatible python interpreter(Python Virtual Machine ) . Note all the parsing , syntax matching compiler thing is usually done in this byte code the leftover is done afterword's . This Byte code file is not usually seen until you are importing modules in the code

  • PVM - Python Virtual Machine is runtime engine responsible for the conversion of Bytecode into Machine Code (Binary code ) . PVM / Python runtime engine also uses some difference finding algorithm which finds the difference between the code and update accordingly in the byte code .

  • Abstract : The code /script is firstly converted to byte code , all the compiler related things are done (syntax finding , parsing and etc. ) , this byte code is the low level compilation of the program , this is machine code( code that gives direct commands to the hardware) .. Byte code then converted into machine code by PVM(Python Virtual Machine) , pvm is a runtime engine for python .

Thankyou