Introduction to python

Official documentation: https://docs.python.org/3/tutorial/index.html

Chinese documentation: http://www.pythondoc.com/pythontutorial3/index.html

Official document description:

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

It translates to:

Python is an easy-to-learn and powerful programming language. It has efficient high-level data structures and enables object-oriented programming in a simple and efficient manner. Python's elegant syntax and dynamic typing, combined with its interpretability, make it an ideal language for scripting or developing applications in many areas on most platforms.

Below we extract some keywords for explanation:

Easy to learn, powerful programming language

Python is a high-level programming language, so what are the high-level and low-level programming languages?

The order should be:

1. Machine Language

2. Assembly language

3. High-level languages

Machine language: Machine language is a set of machine instructions that a computer can directly recognize and execute in binary code.

Assembly language: Assembly language is a low-level language used in electronic computers, microprocessors, microcontrollers or other programmable devices, also known as symbolic languages.

Assembly language is a symbolic language born to solve the incomprehension of machine language, and uses symbols to represent machine instructions.

1
2
3
4
5
操作:寄存器BX的内容送到AX中
  
1000100111011000               机器指令
  
mov ax,bx                     汇编指令

However, only machine instructions can be read by a computer, so how can a computer execute a program written by a programmer with assembly instructions? At this time, a translation program that can convert assembly instructions into machine instructions is required, and such a program is called a compiler. The programmer writes the source program in assembly language, and then uses the assembly compiler to compile it into machine code, which is finally executed by the computer.

High-level language: High-level language is mainly relative to assembly language. It is programming that is closer to natural language and mathematical formulas. It is basically separated from the hardware system of the machine and writes programs in a way that is easier for people to understand. Such as popular Java, C, C++, C#, PHP, Python, etc.

Efficient high-level data structures: Python is very efficient. To accomplish the same thing, other languages ​​require dozens or even hundreds of lines. Python may only need a few lines, which will be realized in the process of learning.

Object orientation: Python fully supports object orientation

dynamic type

 

The so-called dynamically typed language means that the type check is done at runtime. For example, whether the following code is legal or not will not be judged until runtime (note that it is the type judgment at runtime):

 

1
2
def  sum (a, b):
     return  +  b

The type judgment of statically typed languages ​​is to judge before running (such as the compilation stage). For example, C# and java are statically typed languages. In order to achieve polymorphism, statically typed languages ​​will adopt some type identification methods.

 

explanatory

Computers cannot directly understand any language other than machine language, so the programming language written by the programmer must be translated into machine language before the computer can execute the program. Tools that translate other languages ​​into machine language are called compilers.
There are two ways for the compiler to translate: one is compilation and the other is interpretation. The difference between the two approaches lies in the time point of translation. When a compiler runs in interpreted mode, it is also called an interpreter.
Compiled languages: C/C++, Pascal/Object Pascal (Delphi)
Interpreted languages: Java, JavaScript, VBScript, Perl, Python, Ruby, MATLAB 
 
From: Baidu Encyclopedia, Python official documentation
Replenish:

To implement a language on a specific computer, the first thing to determine is the virtual computer that represents the semantic interpretation of the language. A key question is whether the basic representation of the program during execution is the machine language on the actual computer or the machine language of the virtual machine. This question determines the implementation of the language. According to the answer to this question, programming languages ​​can be divided into two categories: compiled languages ​​and interpreted languages.

  1.   Compiled and implemented languages, such as: C, C++, Fortran, Pascal, Ada. A source program written in a compiled language needs to be compiled, assembled and linked to output object code, which is then executed by the machine. The object code is composed of machine instructions and cannot be run independently, because the source program may use some library functions that cannot be interpreted and referenced by the assembler, and the library functions are not in the source program. At this time, the linker also needs to complete the external reference and target template. The link task that is called can finally output the executable code.
  2.   Interpreted language, the interpreter does not generate target machine code, but generates intermediate code. This intermediate code is different from machine code. The interpretation of intermediate code is supported by software and cannot be directly used on hardware. This software interpreter usually results in less efficient execution, and programs written in an interpreted language are executed by another interpreter that can understand the intermediate code. Different from the compiled program, the task of the interpreter is to interpret the statements of the source code into executable machine instructions one by one, without translating the source program into object code and then executing it. For an interpreted language, a special interpreter is needed to execute the program, and each statement can only be translated when it is executed. This interpreted language translates every time it is executed, so it is inefficient.
  3.   Java interpreter, java is very special, java needs to be compiled, but it is not directly compiled into machine language, but compiled into bytecode, and then the bytecode is executed in an interpreted way on the Java virtual machine. Python also uses a similar method, first compiling python into python bytecode, and then a special python bytecode interpreter is responsible for interpreting and executing the bytecode.
  4.   Python is an interpreted language, but for efficiency reasons, a compiled method is provided. After compiling, the pyc file is obtained and the bytecode is stored. Python is very similar to java, but the difference between java and python is that python is an interpreted language, so compiling bytecode is not a mandatory operation. In fact, compiling is an automatic process and generally does not care about it The presence. Compiling to bytecode can save time loading modules and improve efficiency.
  5.   In addition to efficiency, the form of bytecode also increases the difficulty of reverse engineering, which can protect the source code. This is only a certain degree of protection, and decompilation is still possible.

 

From: http://blog.csdn.net/clarkchenhot/article/details/52092209

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325259678&siteId=291194637
Recommended