Execution process of Python program

Hello, everyone, happy May Day, where have you traveled? After playing, spend some time to study and learn to make yourself stronger. In this issue, I will share with you the process learning of Python program execution.

I have introduced to you the introduction of the Python language, the installation of the Python environment, and the selection and installation of the IDE. In this issue, I will officially enter the learning of the Python language. First, I will learn the execution process of the Python language and understand the execution method.

Two ways of program execution

  1. Compilation and execution means that the source program is first compiled into machine language by a compiler, that is, an executable file that the machine can directly execute, and then executed. That is, compile first and then execute. After the entire compilation, it can be run multiple times, cross-platform, and the operation efficiency is high.
    Compiled languages ​​include: C, C++, Java, etc.
    **Advantages: **Compilers generally precompile and optimize the source code. Because it is compiled only once and not compiled at runtime, the compiled language has high execution efficiency and can run independently from the language environment.
    Disadvantages: After compiling, if you modify the code, the entire module will be recompiled. When compiling, machine code will be generated according to the environment. There will be problems when transplanting between different operating systems. Different executable files need to be compiled according to the operating system.
  2. Interpretation execution means that the source program is executed while interpreting, that is, direct execution. Each execution requires a sentence-by-sentence translation, and the execution efficiency is low.
    Interpreted languages ​​include : Python, PHP, JavaScript, etc.
    Advantages : good platform compatibility, can run in any environment, provided that an interpreter is installed, it can also be understood as a virtual machine. Flexible, the code can be modified at any time, the deployment is fast, and there is no need to stop for maintenance.
    Disadvantages : It needs to be re-interpreted every time it runs, and the running efficiency is low.

Diagram of different execution methods

The following figure shows the execution process of different types of languages.
insert image description here
Compiled languages ​​cannot cross platforms in two aspects:
1. Executable programs cannot cross platforms, and the suffixes of executable files in different operating systems are inconsistent, indicating that the internal structure is different and batches are not compatible; for example, under Windows The exe program cannot be run under the Linux platform.
2. The source code cannot be cross-platform. The functions, types, variables, etc. supported by different platforms may be different. A source program written on one platform cannot be compiled and executed on another platform.

Interpreted languages ​​are different.
Interpreted languages ​​need to convert and execute each time the program is executed. Which source codes are used to convert which source codes into machine codes. If different functions are to be implemented each time the program is executed, then the converted The source code is also different. Since the source code needs to be executed for each execution, its execution efficiency is very low, and the interpreted language cannot be separated from the development environment.

Guess you like

Origin blog.csdn.net/hallobike/article/details/130462140