First, Python introduction
The founder of Python is Guido van Rossum (Guido van Rossum)
Current Python main application areas:
• Cloud Computing
· Web Development
• Scientific computing, artificial intelligence
System operation and Maintenance
• Finance: Quantitative trading, financial analysis, etc., as a dynamic language of Python, the language structure is clear and simple, the library is rich, mature and stable, scientific calculation and statistical analysis are very cattle
• Graphical GUI
What kind of language is Python?
Programming languages are categorized mainly from the following perspectives: compiled and interpreted, static and dynamic, strongly typed, and weakly type definition languages.
Compile-and-interpret
Compiled type, such as: c,c++, in fact, it and assembly language is the same: there is a responsible Fan Yi program to convert our source code, production of the corresponding executable code. This process is a bit more professional, it becomes a compilation (Compile), and the program responsible for compiling naturally becomes the compiler (Compiler). If we write the program code is contained in a source file, then usually compiled after the direct generation of an executable file, we can run directly. For more complex projects, in order to facilitate management, we usually spread the code in various source files, as different modules to organize. When you compile individual files, you generate the target files (object file) instead of the executable file that you said earlier. Typically, a source file is compiled with a target file. The contents of these target files are basically executable code, but because they are only part of the entire project, we cannot run them directly. After all the source files have been compiled, we can finally "package" these semi-finished target files into an executable file, which is the responsibility of another program, because this process seems to be to assemble the target file containing executable code, so called link, The program that is responsible for linking is called the link program (Linker). In addition to linking the target file, there may be a variety of resources, such as icon files, sound files, etc., but also responsible for removing redundant duplication of code between the target files, etc... Once the link is complete, you will generally get the executable file we want.
Interpretation, in the literal sense, compilation and interpretation have the meaning of translation, the difference is that the timing of the translation is not quite the same. For example: read a foreign language book that does not understand, you can find a translator, give him enough time to translate the whole book from beginning to end, and then the native language version of the book to read to you, or, let the translation of a sentence to you, if you want to look back to a Zhangjie, he also has to re-translate to you.
Two ways, the former is equivalent to the compiler: all the code is converted to machine language, and then written into the executable file, and the latter is equivalent to the interpretation: in the first moment of the program run, there is only the source program and no executable program, and every execution of the program to the source program, a command, There will be a shell called an interpreter that transforms the source code into binary code for execution, and in general, explains, executes, interprets, executes ... Therefore, the interpretation procedure is inseparable from the interpretation procedure. Like the early basic is a classic interpretation of the language, in order to execute the basic program, you have to enter the basic environment before you can load the program source files, run.
Interpreted languages are doomed to be slower than compiled languages and, in some cases, even hundreds of times times slower.
Compiled and interpreted type, both have pros and cons. The former performs fast and has low system requirements under the same conditions, so it is used like developing operating system, large-scale application, database system and so on. such as C + +, Pascal/object Pascal (Delphi), VB and other basic can be regarded as a compilation language, and some Web scripts, server Scripts and auxiliary development interface such as the speed requirements are not high, the compatibility of different system platforms have certain requirements of the program is usually used in interpreted language , such as Java, JavaScript, VBScript, Perl, Python, and so on.
Compilation and interpretation of the pros and cons of each other, so a number of emerging languages have a tradeoff between the two trends, such as the Java language, although relatively close to the interpretation of the characteristics of the language, but before execution has been pre-compiled, the generated code is between the machine code and Java source code between the intermediary code, Runtime is interpreted by the JVM (the Java Virtual Machine platform, which can be interpreted as an interpreter). It retains the high abstraction and portability of the source code and has completed much of the precompiled work on the source code, so it is much faster to execute than the "pure interpreter" program. and languages like VB6 (or previous versions), C #, Although the surface is generated by the. exe executable file, but the actual build after VB6 compiled is also a kind of intermediary code, but the compiler in front of a section of the automatic call to an external interpreter code (the interpreter is independent of the user-written program, stored in a DLL file of the system, all the executable program generated by VB6 compilation will be Use it) to explain the actual program body being executed. C # (and other. NET language compilers) generate. NET target code, which is executed by the. NET interpretation system (just like the JVM, which is also a virtual machine platform). Of course, the. NET target code is quite "low-level", closer to the machine language, so it is still considered a compilation language, and its portability is not as strong as Java claims, Java is called "once compiled, everywhere," and. NET is "once encoded, compiled everywhere." In a word, with the development of design technology and hardware, the boundary between the two ways of compiling and interpreting is constantly becoming blurred.
Dynamic language and static language
Usually we call dynamic language, static language refers to dynamic type language and static type language.
Dynamic type language: refers to the language of data type checking during run time, that is, when programming in a dynamic type language, you never have to specify a data type for any variable, and the language will record the data type internally when you assign it to a variable for the first time. Python and Ruby are a typical dynamic type language, and many other scripting languages, such as VBScript, are also dynamic type languages.
Static type language: Contrary to the dynamic type language, his data type is checked during compilation, that is, when writing a program to declare the data types of all variables, C + + is a typical representation of statically typed languages, and other static type languages include C #, Java, and so on.
Strongly typed definition language and weak type definition language
Strongly typed definition language: A language that enforces the definition of a data type. Once a variable is assigned a data type, it is always the data type if it is not cast. Strongly typed languages are type-safe languages.
Weak type definition language: A language in which data types can be ignored. In contrast to strongly typed definition languages, a variable can assign values of different data types.
Strongly typed definition languages may be slightly slower than weak type definition languages, but rigorous performance from strongly typed definition languages effectively avoids many errors. In addition, "The language is not a dynamic language" and "the language is the type of security" is completely no connection between!
For example: Python is a dynamic language, a strongly typed definition language (type-safe language), VBScript is a dynamic language, is a weak type definition language (type unsafe language), Java is a static language, and is a strongly typed definition language (type-safe language). Shell scripts are also weak types
Python is a strongly-typed definition language with dynamic interpretation
The pros and cons of Python
Advantages:
Python's positioning is "elegant" "clear" "simple", so the Python program always looks easy to understand
Development efficiency is very high, Python has a very powerful third-party library
Advanced language
Portability-If you are careful to avoid using system-dependent features, all your Python programs can run on almost any system platform on the market without modification
Scalability-If you need a piece of your critical code to run faster or if you want some algorithms to be private, you can write some of your programs in C or C + + and then use them in your Python program
can be embedded
Disadvantages:
Slow, most of the time the user is not directly aware of, For example, C running a program took 0.01 seconds, Python is 0.1 seconds, so C language directly than Python 10 times times faster, is very exaggerated, but can not be directly perceived by the naked eye, because a normal person can perceive the minimum unit of time is 0.15-0.4s around. In fact, most of the time the python sentence can fully meet the requirements of the program speed
The code cannot be encrypted, because Python is an interpreted language, and its source codes are stored in clear-text form.
Threads do not take advantage of multi-CPU problems, which is one of the most common drawbacks of Python, the Gil, the Global Interpreter lock (interpreter lock), is a tool that the computer programming language interpreter uses to synchronize threads so that only one thread executes at any moment, The python thread is the native thread of the operating system. On Linux for Pthread, on Windows for Wthread, the execution of threads is fully dispatched by the operating system. A Python interpreter process has a main thread and the execution thread for multiple user programs. Multi-threaded parallel execution is prohibited even on multicore CPU platforms due to the existence of the Gil.
Python interpreter
When we write the Python code, we get a text file that contains the Python code with a. py extension. To allow the code, the Python interpreter is required to execute the. py file.
CPython: The most widely used interpreter. All the code in the tutorial is executed under CPython.
IPython: Based on an interactive interpreter on the CPython
PyPy: Its goal is the speed of execution. With JIT technology, Python code is dynamically compiled (not explained), so it can significantly improve the execution speed of Python code.
Jython: is a Python interpreter running on the Java platform
IronPython: Similar to Jython, is running on the Microsoft. NET Platform
Ii. History of Python
• 1989, Guido began writing the Python language compiler
• 1991, the first Python compiler was born.
python 2.0-october 16,2000
python 2.6-october 1,2008 transition version
python 2.7-july 3,2010 transition version
python 3.0-december 3,2008
In November 2014, it is announced that Python version 2.7 will be supported by 2020 and will not have 2.8 versions.
Third, Python 2 or 3?
Python 2.x is a past style, Python 3.x is now and future language
All updates to the standard library will only be available in the 3.x version
Support for Unicode
Programmer can perceive the change:
Who else doesn't support Python3?
Twisted
Python installation: slightly.
This article is from the "Tread Footprints" blog, please be sure to keep this source http://zoucuo.blog.51cto.com/962798/1884095
Python Learning Notes (Python development introduction)