Why python is an interpreted language?
Python is one of the most popular interpreted languages, but have you ever thought about why Python is called an interpreted language while other programming languages like C, C++, Java, etc., generate results after compilation? So, you might be curious about what is this interpreted language. And how is this different from the language which generates results after compilation?
To answer the question, we must know what interpreted means.
Interpreted in simple terms means running code line by line. It also means that the instruction is executed without earlier compiling the whole program into machine language.
Now, let us discuss how Python works as an interpreted language. Consider a scenario where you are trying to run a python code, but unfortunately, you have made some mistakes at the bottom of the code. You will find that there is an error generated for obvious reasons, but along with the error, you will find the output of the program till the line of the program is correct. This is possible because Python reads the code line by line and generates output based on the code. Whenever it finds any error in the line, it stops running and generates an error statement.
Python is Both Compiled as well as Interpreted
"Python is an interpreted language", is the most common saying, which is also written in various books, but the hidden fact is Python is both compiled as well as an interpreted language. This means when we run a python code, it is first compiled and then interpreted line by line. The compilation part is mostly hidden from the user. While running the code, Python generates a byte code internally, this byte code is then converted using a python virtual machine (p.v.m) to generate the output.
Now, let us try to prove the fact python is both compiled as well interpreted.
Note: The compile part gets deleted as soon as the code gets executed so that the programmer doesn't get onto unnecessary complexity.
Comments
Post a Comment