Let’s assume that we write a python program with the name calc.py. Here, calc is the program name and the .py is the extension name. All programs written in python has an extension name .py. After completing the program next step is to compile the program using the Python compiler.
The sequence of Python program compilation.
Program Source Code –> Byte Code –> Machine Code –> Program Output.
Python compiler actually translates program code into another code which is known as byte code. Byte code represents a fixed set of instruction that represents all operations like arithmetic operations, comparison operator, operations memory-related operations, etc. which run on an operating system and hardware.
Thus, byte code is a platform independent code and each instruction size is 1 byte. The corresponding byte code for our sample calc.py program would be calc.pyc.
Now, the next step is to run the is to run a program if you directly give the bite go to the computer it cannot execute them. Computers can only execute byte code which comprises 0s and 1s since the machine can only understand binary codes.
Thus, it is necessary to convert the byte code into binary code so that the computer can understand. Hence, Python Virtual Machine (PVM) actually translate byte code into Machine code.
Python Virtual Machine uses an interpreter to understand the byte code and converts it to machine code. PVM first understands the computer operating system and processor and then convert byte code into binary code. This machine code instruction is executed by the processor to generate output.
An interpreter translator program source code line by line. Hence, it is slow. The interpreter that is found inside the PVM run the Python program slowly. In order to rectify this problem, certain version of Python a compiler is added to the PVM. This compiler also converts the byte code into machine code but faster than interpreter this compiler is called JIT (Just In Time). The advantage of JIT (i.e. Just In Time) compiler is to improve the speed of execution of the Python program and does improve the performance.
Normally, when you compile a Python program, you cannot see calc.pyc and machine code because the entire process is done internally in the memory and final output is visible.
Note: JIT compiler is not available with all Python version.