In the previous part, we saw a very simple Hello World program. We saw that whatever is written inside the print() function is shown as the output. But how does it work? We will discuss this in detail in this part.

From running a program to displaying the output, there are several steps involved that we usually don’t see. These intermediate steps can be divided into two parts:

  • Conversion to Byte Code
  • Python Virtual Machine or PVM

Conversion to Byte Code

Python first converts the source code into byte code. Simply put, this is a medium that translates the written program into a language suitable for the machine. Byte code is independent of the machine, a completely autonomous medium that can execute tasks much faster than the source code.

We can see the bytecode on our computer or machine. In the directory where our source file is located, the byte code is generated in a folder named pycache. However, it is saved with the .pyc extension instead of .py, where pyc stands for python compiled. There is a specific naming convention for it.

Suppose you have written a program and saved it as Then its bytecode might be named test.cpython-38.pyc, indicating that this Python interpreter is cpython and the version is 3.8.

Once compiled into byte code, it runs from the byte code as long as no changes are made to the source code.

Python Virtual Machine (PVM)

The Python Virtual Machine is Python’s runtime engine and the final step. It primarily converts the program into instructions.

0 0 votes
Article Rating
Would love your thoughts, please comment.x