Basic article D1--The path of Python learning

Source: Internet
Author: User

Programming language classification

1. Compile-and-interpret

Compiler: There is a program responsible for translating the source code to convert, generate executable code. This process is called compiling (compile), and the program responsible for compiling is called the compiler (compiler). When the source code is compiled, an executable file is generated.

Compiler-based language operation procedures:

Pros: Compilers typically have pre-compiled procedures to optimize code. Because the compilation is done only once, the runtime does not need to compile, so the program execution of the compiled language is highly efficient. Can run independently from the language environment.  

Cons: After compilation, the entire module needs to be recompiled if modifications are required. When compiling the machine code according to the corresponding running environment, porting between different operating systems will be problematic, and you need to compile different executables according to the operating system environment you are running.  

Explanatory: literally, "compilation" and "Interpretation" do have the meaning of "translation", and their difference is that the timing of the translation is not very similar. For example: If you are going to read a foreign language book, and you do not know it, then you can find a translator, give him enough time to translate the whole book from beginning to end, and then give you the native language version of the book to read, or you can immediately let the interpreter assist you to read, let him sentence to you to translate, If you want to look back at a chapter, he will have to re-translate it for you.  

Pros: Good platform compatibility, can be run in any environment, provided the interpreter (virtual machine) is installed. Flexible, modify the code when the direct modification can be quickly deployed, without downtime maintenance.  

Cons: Every time you run, you have to explain it again, performance is not as good as the compiled language.  

Compiled and interpreted type, both have pros and cons. The former because the program execution speed, the same conditions on the system requirements are low, so like the development of operating systems, large-scale applications, database systems, such as the use of it, such as C + +, Pascal/object Pascal (Delphi), VB and other basic can be regarded as compiled language, and some web script , server scripts, and auxiliary development interfaces for applications where speed requirements are low and the compatibility of different system platforms are required, it is common to use explanatory languages such as Java, JavaScript, VBScript, Perl, Python, and so on.

Dynamic language and static language
Usually we call dynamic language, static language refers to dynamic type language and static type language.  

(1) Dynamic 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.  

(2) Static type language: The static type language is just the opposite of the dynamic type language, its data type is checked during compilation, that is, when the program is written to declare the data type of all variables, C + + is a typical representative of static type language, and other static type language has C#, Java and so on .  

Strongly typed definition language and weak type definition language

(1) Strongly typed definition language: A language that enforces the definition of a data type. In other words, once a variable is assigned a data type, it is always the data type if it is not cast. For example: If you define an integer variable A, the program simply cannot treat a as a string type. A strongly typed definition language is a type-safe language.  

(2) Weakly typed 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 language may be slightly slower than weak type definition language, but the rigor of strong type definition language can effectively avoid 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 and is a strongly typed definition language (type-safe language); VBScript is a dynamic language and is a weak type definition language (type unsafe language); Java is a static language and is a strongly typed definition language (type-safe language).  

Python pros and cons

See the pros first

    1. python Elegance" , "clear", "simple", easy to get started, and going deeper in the future, you can write very, very complex programs.  

    1. Development efficiency is very high, Python has a very powerful third-party library, basically you want to achieve any function through the computer, the Python official library has the corresponding modules to support, directly download the call, on the basis of the base library to develop, greatly reduce the development cycle, to avoid repeating the wheel.  

    1. High-level language ———— when you write programs in the Python language, you don't have to consider the underlying details such as how to manage the memory used by your program

    1. Portability ———— because of its open source nature, Python has been ported on many platforms (modified to make it work on different platforms). 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

    1. Scalability ———— If you need a piece of your critical code to run faster or 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.  

    1. Embeddable ———— You can embed python into your C + + program to provide scripting functionality to your program users.  

Look at the disadvantages again:

    1. slow, Python runs slower than C and slower than Java, so this is the main reason why so many so-called Daniel disdain to use Python, But in fact, this refers to the slow running speed in most cases the user is not directly aware of, must rely on testing tools to reflect, such as you use C a program to spend 0.01s, Python is 0.1s, so C language directly than Python 10 times times faster, is very exaggerated, But you can not directly perceive by the naked eye, because a normal person can perceive the time minimum unit is 0.15-0.4s around, haha. In fact, in most cases python has been fully able to meet your requirements for the speed of the program, unless you want to write to the speed of the most demanding search engine, in this case, of course, it is recommended that you use C to real now.  

    1. Code can not be encrypted, because Python is an explanatory language, its source code is stored in the form of a name, but I do not think this is a disadvantage, if your project requires that the source codes must be encrypted, then you should not use Python in the beginning to implement.  

  1. Threads do not take advantage of multi-CPU problems, which is one of the most common drawbacks of Python, the Gil is the global interpreter lock (interpreter lock), which isComputer programming languageInterpreterthe tool used to synchronize threads so that only one thread executes at any moment, and the Python thread is the native thread of the operating system. On Linux for pthread, on Windows for win thread, 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. A compromise solution to this problem is discussed in more detail later in the Threads and Processes section.  

before you learn, learn Binary

Principles and Transformations

Character Trivia

ascii  ( Chinese character ) -->gb2312 (1980): 7000+ Kanji -->gbk1.0 (1995) : 2w+ Kanji   --GB18030 (2000): 27xxx Kanji  

Unicode ( two bytes, memory-intensive )---> UTF-8 (en:1 Byte, Cn:3 BYTES)

Processing of characters in different versions of Python

Python 2.x: Default to ASCII characters, use the Chinese front to add an annotation-*- coding:utf-8-*-

Python 3.x: Default is UTF-8 character, Chinese is supported by default

Python language annotations

Single-line Comment : #

Multiline Comment: three single or double quotation marks

Basic article D1--The path of Python learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.