程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Childrens python programming 5-python program execution process

編輯:Python

One 、 Compilation and interpretation

Source code for a computer , It's all unreadable , Computers know only binary instructions . therefore , Want the program to be executed , So naturally, we need to convert the source code into binary instructions first , That's machine code .

that , When to make the transition ?

Some languages require that the code must be converted in advance , This is a compiled language , The conversion tool used is called compiler , such as C Language 、C++. Some languages can be executed and transformed at the same time , Where it's used, it's transferred , This is interpretative language , The transformation tool used is called interpreter , such as python、javascript.

compiler

Compilation is from source code ( It's usually a high-level language ) To object code that can be executed directly by a computer or virtual machine ( Usually low-level language or machine language ) Translation process of .

Interpreter

Interpret the relatively high-level program code into the machine code that the computer can run directly .

Python Interpreter [1]

When python After the package is installed on the machine , It generates some components : Include at least one interpreter and a set of support libraries . Compiling python The code has to run in the interpreter .

Python The interpreter consists of a compiler (compiler) And a virtual machine constitute , The compiler is responsible for converting the source code into a bytecode file , The virtual machine is responsible for executing bytecode . therefore , Interpretive languages also have an implicit compilation process , However, the compilation process does not directly generate object code , Instead, generate intermediate code ( Bytecode ), Then the bytecode is interpreted and executed line by line through the virtual machine .

Two 、 From programming to operation

Write a print “Hello” A string of python Program :

print(‘Hello’)

Carriage return operation :

The above code actually goes through two steps [1]:

1. Compile the source code into “ Bytecode ”, Put the source code file xx.py Compile into a bytecode file xx.pyc.

2. take “ Bytecode ” Forward to “ virtual machine ”,“ virtual machine ” perform “ Bytecode ” Convert to binary language and run on computer hardware .

 Execution process [2]:

3、 ... and 、 reference

[1]: https://www.jb51.net/article/250335.htm

[2]: 【Python】 Talking about Bytecode + virtual machine (Python Interpreter )_ Where is Wen Shao's blog -CSDN Blog


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved