Introduction to Python Interpreter & Program Execution:

M3-R5.1 · Chapter 3: Introduction to Python · 6 min read

Introduction to Python Interpreter and program execution

How Python Interpreter Works?

We have learned that Python is an interpreted language. Well, what does it mean? It means that we actually run another program that is responsible for reading our source code and running it Top To Bottom. In Python, this “another program” we just referred to iscalled an  Interpreter. Simply put, an Interpreter is a kind of program that executes other programs. Now, this interpreter itself can be implemented as a C program, or as a set of Java classes, or can be written in Python itself. The standard Python interpreter, though, is written in C, called the CPython.

  • Stage 1: Create and save a Python source code file (.py). Python Compiler begins reading the file.
  • Stage 2: Compiler converts the source code into platform- independent bytecode (.pyc) after checking for syntax and structural errors.
  • Stage 3: Bytecode is executed by the Python Virtual Machine (PVM), which translates it into machine code (binary).
  • Stage 4: Handling Errors (If Any)  If the program has errors, the Python interpreter stops execution and shows an error message. 
  • Stage 5: Machine code is executed by the CPU to produce the final output on the screen.


Method to install Python

  • Step – 1 - Download Installer: Go to the Python website (https://www.python.org/) , download the Python 3 installer for your OS.
  • Step – 2- Run Installer: Double-click to start installation.
  • Step – 3- Select Options: On Windows, check "Add Python to PATH" and choose "Install Now" or customize settings.
  • Step – 4- Finish Setup: Complete installation and close the installer.
  • Step – 5- Installation: Open a terminal, type python --version or python3 --version to confirm successful installation.
  • Step --6 - Verify pip installation by enter pip -v

After installation is successfully completed, you can start Python in the following ways These are:

(a) Python Shell – Interactive mode (Command line)

(b) Python Editor – Script mode (Integrated Development Environment – IDLE)

Interactive Mode (Python Shell)

Interactive mode of working means you type the command one at a time, and Python executes the given command and gives you output. An interactive interpreter of Python is also called Python Shell.

Click on Start Buttons--> Search Python ----> Press Enter

The Python interpreter can be used as a calculator. If you just want to do simple calculations, you can type numbers and operators and press Enter key to see the result, If you type 6+6, the interpreter displays result 12. You can Also Print statements Like Displaying “Hello World” in python type print (“Hello World”) and Press Enter.

Script Mode (Python Editor)
IDLE (Integrated Development and Learning Environment)

It is an integrated development environment (IDE) for Python. The Python installer for Windows contains the IDLE module by default. The interactive mode does not save commands entered by the user. But if you want to save all the commands in the form of a program file and see all output lines together then the script mode of Python is used. A program stored in a file (usually one that will be interpreted) is called a script. Python script mode is basically used for writing programs, i.e., a set of instructions that can be saved for further use.

How to Open Scriptive Mode and Run a Program?
Step – 1 – Press window Button And Search IDLE it shows IDLE(Python 3.8.0 64-bit) click on this

It Shows This Type Interface ↓ This is Python Shell



Step – 2 –Click on File Menu and Select option New file Or Press Ctrl + N




It shows This Type Interface ↓



Step – 3 – Write your Program ↓



Step – 4 – Go to the file menu and select Save or Save as option or Press Ctrl + S it will display Save As Dialog box ↓


Put the name of file and save the file.
Step – 5 –Running a Program. To run a program, module or script, make sure it is opened in the text editor, and choose Run —> Run Module or Press F5 key. See below Figure . ↓



Step – 6 –See the Output. ↓