Interpreted and Interactive Python
Let's start with understanding the interpreted nature of python.
Interpreted Python
Unlike C/C++ etc, Python is an interpreted object-oriented programming language. By interpreted it is meant that each time a program is run the interpreter checks through the code for errors and then interprets the instructions into machine-readable bytecode.
An interpreter is a translator in computer's language which translates the given code line-by-line in machine readable bytecodes. And if any error is encounterd it stops the translation until the error is fixed. Unlike C language, which is a compiled programming language. The compiler translates the whole code in one-go rather than line-by-line. This is the reason why in C language, all the errors are listed during compilation only.
# Demonstrating interpreted python
print "\n\n----This line is correct----\n\n" #line1
print Hello #this is wrong #line2
In the above illustration, you can see that line 1 was syntactically correct and hence got successfully executed. Whereas, in line 2 we had a syntax error. Hence the interpreter stopped executing the above script at line 2. This is not valid in the case of a compiled programming language.
The illustration below is a C++ program, see that although line 1 and line 2 were correct than also the program reports an error, due to an error on line 3. This is the basic difference between interpreted language and compiled language.
// Demonstrating Compiled language
#include<iostream>
using namespace std;
int main()
{
cout<<"---This is correct line---"; // line 1
cout<<"---This line is also correct---"; // line 2
cout "this is Incorrect Line" // line 3
return 0;
}
Interactive Python
Python is interactive. When a Python statement is entered, and is followed by the Return key, if appropriate, the result will be printed on the screen, immediately, in the next line. This is particularly advantageous in the debugging process. In interactive mode of operation, Python is used in a similar way as the Unix command line or the terminal.
The interactive Python shell looks like:
Interactive Python is very much helpful for the debugging purpose. It simply returns the >>>
prompt or the corresponding output of the statement if appropriate and returns error for incorrect statements. In this way if you have any doubts like: whether a syntax is correct, whether the module you are importing exists or anything like that, you can be sure within seconds using Python interactive mode.
An illustration for interactive python is shown below: