/    /  Python – Interpreter

Python – Interpreter

In this tutorial you will learn python in detail.


Python interpreter takes the code that you write and converts it into the language that computer’s hardware understands.

It does this each time you run a python script.

Interpreter executes the code line by line.

As the user enters the command in Python shell, interpreter execute it and displays the result.

For Python shell, open command prompt, write Python and press enter.




As you can see, three Greater Than symbols (>>>) appears on the Python prompt. Now you can enter a single statement as shown below to get the result.


Modules vs scripts


Scripts are top-level files, intended for execution by the user

Modules are intended to be imported


Execute Python Script:


If you can see the above example Python shell executes only a single line of statements. In order to execute multiple statements, create a Python file with extension .py, and write the Python scripts.

Example shown below:




There are a number of implementations of python.


Different python implementations

CPython- the core implementation of the language

Jython- written in Java

PyPy- witten in Python

IronPython – targets.NET

MicroPython -runs on microcontrollers


How does Python run a script


Well, internally, four things happen in a REPL:
i. Lexing- The line of code into tokens by lexer.
ii. Parsing- The parser uses these tokens to generate a structure, here, an Abstract Syntax Tree, to depict the relationship between these tokens.
iii. Compiling- This AST is turned into code object(s)by compiler.
iv. Interpreting- The interpreter executes each code object.