How does the Python Program work in your computer

How does the Python Program work in your computer

Python is a very easy and popular programming language due to its simplicity and demand. Many of us prefer this programming language because of its ease of use. Despite programming in Python, many of us do not know how Python works. Through this article, today we will try to understand that.

Python

Python is a high-level interpreted programming language. Unlike languages like C or C++, it does not require a compiler to run the program. Python executes line by line.

Compiler & Interpreter

A compiler translates the entire code into machine code at once. On the other hand, an interpreter translates line by line.

Let's move on to the main discussion.

Before running a program, we write the program in a file and save it with a specific extension according to the language. In the case of Python, we use .py.

Let's assume we are going to write a Hello World program. First, we create a file named hello.py.

Then, we open the file in any text editor and write our code there.

When we run the file, what happens is our main topic for today.

Before running a Python program, it is essential to have a Python interpreter installed on your computer.

After running the code, the Python interpreter reads the code line by line and translates it into bytecode/machine code. Computers fundamentally understand machine code.

Bytecode is a set of instructions for the developer or programmer. It is saved in a .pyc file. Through the Python Virtual Machine (PVM), the bytecode/machine code is translated and executed, displaying the expected output.

When the Python interpreter reads each line and translates it into bytecode, the program stops executing, and the error message is displayed if there is any error or other issue.

This is essentially how a Python program runs on a computer.

List of some Python interpreters:

  • CPython (official Python interpreter and the standard one)

  • JPython/Jython

  • PyPy

  • RubyPython