Is python an interpreted language?

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

Is python an interpreted language?
Is python an interpreted language
Is there an algorithm in python language
Python is a cross-platform language code
Is python language free or paid?
Everything in Python is an object
Python 3.9 is here!
What is an anonymous function in Python
2.3 Python language foundation
Why python is popular
Python is short-crawling music
Python is short-world epidemic map
Python is short _SVM test
Is python code case sensitive
What is introspection in python
What is object-oriented in python
What is Python variable scope
Why call python a glue language
What is list comprehension in python
Is there function overloading in python
Python deep copy is not perfect
Python judges that it is empty
What is the use of Python
Can python become a mainstream language?
Is python suitable for data mining
CentOS 7 configure Python language development environment
Is python crawler easy to learn