From Brij kishore Pandey.
Letโs walk through a simplified guide to understanding how your Python code becomes a functioning program:
1๏ธโฃ ๐ช๐ฟ๐ถ๐๐ถ๐ป๐ด ๐๐ต๐ฒ ๐๐ผ๐ฑ๐ฒ: We start with typing out our Python program in a text editor, saving it as a โ.pyโ file.
2๏ธโฃ ๐ฃ๐๐๐ต๐ผ๐ป ๐๐ป๐๐ฒ๐ฟ๐ฝ๐ฟ๐ฒ๐๐ฒ๐ฟ: When we run the program, itโs sent into the Python Interpreter, which is made up of two parts:
๐๐ผ๐บ๐ฝ๐ถ๐น๐ฒ๐ฟ: This part changes our Python code into something called byte code. This byte code is saved in a โ.pycโ file, helping our program run faster the next time.
๐ฃ๐๐๐ต๐ผ๐ป ๐ฉ๐ถ๐ฟ๐๐๐ฎ๐น ๐ ๐ฎ๐ฐ๐ต๐ถ๐ป๐ฒ (๐ฃ๐ฉ๐ ): The PVM uses the byte code and follows the instructions one by one until the program is finished or runs into an error.
3๏ธโฃ ๐๐ถ๐ฏ๐ฟ๐ฎ๐ฟ๐ ๐ ๐ผ๐ฑ๐๐น๐ฒ๐: If our program uses library modules from Pythonโs standard library or elsewhere, these are also changed into byte code. The PVM then uses this byte code, allowing our program to use the features of these modules.
4๏ธโฃ ๐๐ฟ๐ผ๐บ ๐๐๐๐ฒ ๐๐ผ๐ฑ๐ฒ ๐๐ผ ๐ ๐ฎ๐ฐ๐ต๐ถ๐ป๐ฒ ๐๐ผ๐ฑ๐ฒ: The PVM further converts the byte code into machine code, which is a series of 1s and 0s. This machine code is what your computerโs brain, the CPU, can directly understand.
5๏ธโฃ ๐ฅ๐๐ป๐ป๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ: After the machine code is ready, your computer uses it to run your program. And there you have it! Your Python program is up and running.
Understanding the transition from Python code to a running program provides insight into how Python, as an interpreted language, bridges the gap between the high-level code we write and the low-level operations performed by a computer.