Internal Working Of Python

Preeti AdhikariPreeti Adhikari
1 min read

Python is a programming language widely recognized for its simple syntax, readability, and versatility. Have you ever wondered how it operates internally? If not, this article is definitely for you.

  1. Python Source Code: When we write a Python program (for example, python.py), we use a high-level, human-readable language.

    For instance, print("Hello, world!")

    This marks the beginning of the Python execution process.

  2. Compilation to Bytecode: Our source code (Python.py file) is then compiled into bytecode. Bytecode is an intermediate code generated by compiling the source code. It is not machine code and is platform-independent. Bytecode must be interpreted or further compiled to run on any machine.

    After compilation, a .pyc file is created inside a pycache folder.

    Example: Program.pyc

  3. Python Virtual Machine (PVM):

    Once bytecode is prepared, it is passed to the Python Virtual Machine (PVM).

    PVM is the component of Python that executes your bytecode. It reads each instruction and performs the corresponding operation.

    Responsibilities of PVM:

    • Memory management

    • Garbage collection

    • Execution of bytecode

    • Error handling

    You can think of PVM as the "engine" of Python that drives the code.

    These are the three fundamental functions that work internally to successfully execute a Python program. I hope you found this information useful.

    Until next time, love animals and keep coding.

0
Subscribe to my newsletter

Read articles from Preeti Adhikari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Preeti Adhikari
Preeti Adhikari