Inner Working of Python🧩

Kashish OzaKashish Oza
2 min read

Python is one of the most popular programming languages in the world, and for good reason! It's known for its simplicity, readability, and versatility. But have you ever wondered what happens behind the scene when you run a Python program? Let's take a peek inside! 🔍

How Python actually works?

Conside a file hello.py,

  1. Python Source code is compiled to byte code.

  2. This Byte is sent to python virtual machine for execution.

1. Python virtual machine :

It is a basic software which runs a continous code loop to iterate byte code.

💡
Python is an interpreted language!

Python Virtual machine is also known as Run time Engine or Python Interpreter.

2. Byte Code :

Byte code is low level code and platform indepent.Hence, It runs faster.

This byte code is mostly hidden in python.

The source code is converted in byte code.This byte code is fetched by python virtual machine to run the code. It is python specific interpretation.

💡
Byte code is Not Machine code.

for file hello.py,

.pyc file is created -> compiled python

__pycache__ folder is created, It contains source change and python version.

hello.cpython-312.pyc file is created inside the pycache folder.

It works for only imported files not for top level files.

cpython is a standard implementaion in python.There are various implementation like jython, Iron Python, Stackless, PyPy.

So, This is the internal working of python it might seem complex,but it enables the simplicity of language.

For more detailed video explaination you can watch this:

Happy coding! 💻🐍

0
Subscribe to my newsletter

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

Written by

Kashish Oza
Kashish Oza