Generally speaking, compilation means converting a high-level language into machine code that the CPU can execute. When you compile C, you do exactly this. The result of the compilation is a binary executable file, then your system can run this program directly.
In contrast, the interpretation means this: every time the program runs, it reads a line of code in the source file and executes the corresponding operation, repeating it line by line. Of course, this is how the so-called scripting language works.
In Python, source code is compiled into a lower-level form, which we call bytecode. Bytecode is a series of instructions, similar to the instruction set of the CPU. But the bytecode is not directly executed by the CPU, but executed in the virtual machine. Of course, the virtual machine here does not imitate the environment of the entire operating system, but only provides an environment for bytecode execution.
Another important feature of Python is the interactive command line. You can type a line of Python statement and press Enter to execute it immediately. In fact, even in this process, Python is first converted to bytecode and then executed. The interactive command line feature is not available in many compiled languages. Also because there is no explicit call to the compiler program, many people call the program that executes the Python source file the Python interpreter.
Interpreted and compiled languages
Computers cannot recognize high-level languages, so when we run a high-level language program, we need a "translator" to engage in the process of converting the high-level language into a machine language that the computer can understand. This process is divided into two categories, the first is compilation, and the second is interpretation.
Before the program is executed, the compiled language will perform a compilation process on the program through the compiler, and convert the program into machine language. There is no need for translation at runtime, and just execute it directly. The most typical example is the C language.
Interpreted languages do not have this compilation process. Instead, when the program is running, the interpreter interprets the program line by line, and then runs it directly. The most typical example is Ruby.
Through the above examples, we can summarize the advantages and disadvantages of interpreted languages and compiled languages, because compiled languages have already "translated" the program before the program is run, so "translation" is omitted at runtime. "Process, so the efficiency is relatively high. But we can't generalize, some interpreted languages can also optimize the entire program when translating the program through the optimization of the interpreter, so that the efficiency is close to the compiled language, but can not exceed the compiled language.
In addition, with the rise of languages based on virtual machines such as Java, we cannot divide languages purely into interpreted and compiled languages.
Using Java as an example, Java is first compiled into a bytecode file by a compiler, and then interpreted into a machine file by an interpreter at runtime. So we say that Java is a language that is compiled and then interpreted.
Content expansion:
A frequently heard question is: Is Python an interpreted language? Will it be compiled? This question is not as easy to answer as expected. Like many people knowing the world, they are used to judging something with a simple model. In fact, it contains a lot of details.
Generally speaking, compilation means converting a high-level language into machine code that the CPU can execute. When you compile C, you do exactly this. The result of the compilation is a binary executable file, then your system can run this program directly.
In contrast, the interpretation means this: every time the program runs, it reads a line of code in the source file and executes the corresponding operation, repeating it line by line. Of course, this is how the so-called scripting language works.
But in fact, the above definition has too many limitations. A real language usually adopts various implementation methods in order to have more useful and powerful features. We can understand compilation as more general: the transformation of one language into another language form. Generally speaking, the source language is more advanced than the target language, such as converting C into machine code. Of course, the conversion from JavaScript 8 to JavaScript 5 is also a kind of compilation.
So far, this article on whether python is an interpreted language is introduced. For more related python is an interpreted language, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support ZaLou more in the future .Cn!
Recommended Posts