Open In App

What is Python Interpreter

Last Updated : 06 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Well if you are new to Python you have come across the word interpreters but before knowing about Python interpreters, we need to what is an interpreter, what it will do, the advantages and disadvantages of the interpreter, and so on. Well in this handy article, we will cover the Importance of Interpreters and the pros and cons of using interpreters in Python.

Python Interpreter

Python is an interpreted language developed by Guido van Rossum in the year of 1991. As we all know Python is one of the most high-level languages used today because of its massive versatility and portable library & framework features. It is an interpreted language because it executes line-by-line instructions. There are actually two way to execute python code one is in Interactive mode and another thing is having Python prompts which is also called script mode. Python does not convert high level code into low level code as many other programming languages do rather it will scan the entire code into something called bytecode. every time when Python developer runs the code and start to execute the compilation part execute first and then it generate an byte code which get converted by PVM Python Virtual machine that understand the analogy and give the desired output.

Interpreted Languages: Perl, BASIC, Python, JavaScript, Ruby, PHP.
Compiled Languages: C, C++, C#, COBOL and CLEO.

What are Interpreters?

Interpreters are the computer program that will convert the source code or an high level language into intermediate code (machine level language). It is also called translator in programming terminology. Interpreters executes each line of statements slowly. This process is called Interpretation. For example Python is an interpreted language, PHP, Ruby, and JavaScript.

interpreter

Working of Interpreter

Example: Here is the simple Python program that takes two inputs as a and b and prints the sum in the third variable which is c. It follows sequential as well as functional execution of programs

Python3




a = 3
b = 7
c = a + b
print(c) # output 10


Output

10





How interpreters function in Python?

Python interpreter is written in C programming language as we all know that C is considered as mother of all programming languages, Python interpreter called “CPython”.

Initially in source code analysis, Python get source and check for some Indentation rule and check for errors. if there are any errors Python stops its execution and make to modify to prevent errors. This process is called Lexical analysis in python which states that dividing the source code into list of individual tokens.

In Byte code generation, once the python interpreter receives the tokens, it generates AST (Abstract Structure tree) which coverts to byte code and then byte code can be saved in (.py) extension.

At last, by using Python Virtual Machine, interpreter loads the machine language and PVM converts in into 0s and 1 s which prints the results.

Difference between Compilers and Interpreters

Compiler

Interpreter

It translates a program on a single run

It executes a program line by line.

It is an Fast Process

It is an Slow Process

It generates output in the form of .(exe)

It does not generate any form of outputs.

It utilizes CPU more.

It takes less utilization of CPU

It is used in Production environment

It is maximum used in Programming and development environment.

C, C++, C# are the compiled languages

Python, Ruby, PHP are the interpreted languages.

It takes lot of time to analyze the code structure

It takes less time compared to compilers.

Advantages of using Interpreter

  • It is flexible and error localization is easier.
  • It is smaller in size.
  • It executes line by line execution.

Disadvantages of using Interpreters

  • It takes lot of time to translate.
  • It is slower.
  • It uses lot of storage.

Applications of Interpreters

  • They are used to execute common languages by using editor or an compiler.
  • Easy implementation of self modifying code.
  • Virtualization.
  • Sandboxing.
  • Emulators.

Interpreters of different programming language.

  • Python – PyPy, Stackless Python, Pyston, CPython, Micro Python, and Rust Python.
  • Java – JRocklt, Hotspot.
  • Ruby – CRuby, MRI.

Conclusion

Well done! In this article we have successfully covered what is interpreter to how to run commands using Python interpreters and so on. I hope you found engaging to read this article and note that Interpreter comes under the category of translator in programming terminology. Keep using python interpreter as it provides simplified path for programming and students also finds easy to learn due to its easy implementation and its features.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads