2017-10-4 Oldboy python day3

Source: Internet
Author: User



First, low-level language and high-level language

The original computer programs are expressed in sequence 0 and 1, the programmer is directly using the machine instructions, without translation, from the tape punch input can be executed to achieve results. Later, in order to facilitate the memory, will be used in 0, 1 sequence of machine instructions are signed to help remember, these and machine instruction one by one corresponding mnemonic is the assembly instructions, resulting in the birth of assembly language. Both machine instructions and assembly instructions are machine-oriented, collectively referred to as low-level languages. Because it is a mnemonic for machine instructions for a particular machine, assembly language cannot be independent of the machine (a particular CPU architecture). But assembly language is also to be translated into machine instructions to execute, so there are also the assembly language running on one machine to run on another machine instructions on the method, that is, cross-assembly technology.

High-level language is a computer language from the perspective of human logical thinking, the degree of abstraction is greatly improved, it needs to be compiled into the target code on a specific machine to execute, a high-level language statement often requires a number of machine instructions to complete. High-level languages are independent of machine-specific features that are implemented by the compiler to generate different object code (or machine instructions) for different machines. In particular, how to compile the high-level language to what extent, which is related to the compilation of technology, can be compiled into directly executable object code, can also be compiled into an intermediate representation, and then get to different machines and systems to execute, this situation often need to support the environment, such as the interpreter or virtual machine support, It is a good example that Java programs are compiled into bytecode and then executed by virtual machines on different platforms. Therefore, the high-level language is not dependent on the machine, refers to the different machines or platforms in the high-level language program itself is unchanged, and through the compiler compiled by the target code to adapt to different machines. In this sense, through cross-compilation, some assembler can also obtain the portability between different machines, but this approach is far less portable than the high-level language to facilitate and practical.




Ii. Compilation and interpretation

Compilation is the translation of the source program into an executable target code, translation and execution are separate, and interpretation is the source program translation and execution of a one-time completion, do not generate the target code can be stored. This is only the appearance, the biggest difference between the two is: for the interpretation of execution, the control of the program runtime in the interpreter and not the user program, to compile execution, run-time control in the user program.

Interpretation has good dynamic characteristics and portability, such as the ability to dynamically change the type of variables during interpretation, modify the program, and insert good debugging diagnostic information into the program, and then port the interpreter to a different system, then the program can run on the system porting the interpreter without modification. At the same time, the interpreter also has a lot of shortcomings, such as inefficient execution, occupy large space, because not only to the user program to allocate space, the interpreter itself also occupies a valuable system resources.



The compiler compiles each statement of the source program into a machine language and saves it as a binary file so that the computer can run the program directly in machine language at a very fast speed.
And the interpreter is only in the execution of the program, only one interpretation of the machine language to the computer to execute, so the speed is not as fast as the compiled program to run.




compile-and-interpret
We first look at the compiler type, in fact, it is the same as the assembly language: There is a translation program to convert our source code, generate the corresponding executable code. This process is a bit more professional, called compilation (Compile), and the compiler responsible for compiling is naturally called 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. But for a more complex project, for ease of management, we usually distribute 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, And the program that is responsible for linking is called ... called the link Program (Linker). Link program in addition to link to the target file, there may be a variety of resources, such as icon files Ah, sound files ah what, but also responsible for removing the target file redundancy between duplicate code, and so on, so ... is also very tired. Once the link is complete, you will generally get the executable file we want.

We've probably introduced the features of the compiled language, and now we're going to look at the explanatory type. Well, literally, "compilation" and "interpretation" really mean "translation", but the difference is that the timing of the translation is not the same. 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.

two ways, the former is equivalent to what we just said the compiler: once all the code into the machine language, and then written into the executable, and the latter is equivalent to the interpretation of the type: 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. In an explanatory program, because the program is always in the form of source code, the porting is almost no problem as long as there is a corresponding interpreter. Compiled program Although the source code can also be ported, but the premise is that different systems must be compiled separately, for complex projects, it is really a very small time consumption, and it is likely that some of the details of the place or to modify the source code. Moreover, the interpretation of the program saves the steps of compiling, debugging is also very convenient, editing can be run immediately, do not have to be like a compiled program every small change must be patient waiting for a long compiling ... Linking ... This process of compiling links. However, there are pros and cons, because the interpretation procedure is to put the process of compilation into the implementation process, which determines that the interpretation of the program is destined to be slower than the compilation of a large section, like hundreds of times times the speed gap is not surprising.

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.

However, since the 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 the intermediary code between the machine code and the Java source code, which is interpreted and executed 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 claims to be "compile, execute everywhere", while. NET is "once encoded, compiled everywhere." Oh, of course, these are off-topic. In short, 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.



(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: Static type language is just the opposite of dynamic type language, its data type is checked during compilation, that is, when writing a program to declare all variables of the data type, C + + is a static type language typical representative, other static type language also 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).





With these introductions, we can conclude thatPython is a strongly typed definition language that is dynamically interpreted. So what are the advantages and disadvantages of python that these genes have achieved? Let's keep looking down.



   Advantages and disadvantages of Python:



     



See the pros first


    1. Python's positioning is "elegant", "clear", "simple", so the Python program looks always easy to understand, beginners learn python, not only easy to get started, but also in the future, you can write those very very complex programs.
    2. 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.
    3. 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
    4. 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
    5. 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.
    6. 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 faster than the C language, and slower than Java, so this is the main reason why many so-called Daniel disdain to use Python, but in fact, this refers to the speed of slow in most cases the user is not directly aware of, Must rely on the use of testing tools to reflect, such as you use C a program to spend 0.01s, Python is 0.1s, so c directly than Python 10 times times faster, is very exaggerated, but you can not directly perceive through the naked eye, Because a normal person can perceive the smallest unit of time 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 achieve.
    2. 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.
    3. 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 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.

    2. Computer History                                                                                                                                                                                                                                                                         


    The 32-bit system has the largest memory addressing address: 4GB, for example, if your computer's operating system is 32bit (32-bit), even if your memory bar is 8GB, but the operating system can only address to 4 GB of memory, 64-bit system can address the memory to: 2 of the Party, Similar to the Chinese Galaxy computer.



     


1906: DeForest invented the electron tube, which laid the foundation for the development of computer1907: DeForest applied for the patent of vacuum transistor, the vacuum transistor can be in the "saturation" and "cutoff" state respectively. OS: OS Windows linux Unix Symbian actually Android ( AndroidThe native system is also UNIX. Linux applications: 1. Enterprise Server-Enterprise 2. Embedded 3. Desktop-PC 4. Other scripts: Some commands integrate the foot This is used primarily as a small thing, such as Shell scripting in a Linux operating system.

     3. Computer Fundamentals                                                                                                                                                                                                                                                          


      Variable: variable amount, commonly used as data storage, convenient to call later. Constant: An unchanging amount, such as π.



      common suffix names for Windows operating systems:


  • . txt text document suffix format (notepad)
  • . doc Word Document suffix name
  • . xls Excel suffix name
  • . ppt PowerPoint Program suffix name
  • EXE can execute program suffix name, such as QQ, NetEase cloud music and so on.
  • . jpg. png. jpeg image suffix (you can actually insert a word inside the picture, but don't mind the details)
  • PDF PDF E-book suffix format
  • . mp4. avi. rmvb video suffix format
  • . py Python programming language suffix
  • . Java Java programming language suffix
  • . php php File
  • . js JavaScript language suffix




  4.Python environment variable Configuration                                                                                                                                                                                                                  


Take Windows7 operating system as an example, Bo owner himself is Windows7 operating system.



Right-click Computer-Properties-Advanced system Settings-advanced-environment variables-Locate the path path under the system variable, and then open the suffix with a semicolon section to prevent unrecognized, such as; path



      



5.if Statement-Implement an interesting little program


 
 
1 age_of_princal= 56
2 
3 guess_age = int(input(">>:"))
4 if guess_age == age_of_princal:
5     print("Yes,you got it...")
6 else:
7     print("No,it‘s wrong.")


6. Variables and Constants



  Variable: variable amount, commonly used for storing data, convenient for future calls.



Constants: constant quantities, such as π in mathematics



7.Hello World




Python3.0 or later:


Print ("Hello world! ")


Python3.0 the following versions:


Print " Hello world! "


8. Install Python



If the reader wants to install Python, they can go to Python's website and download it.



9. Differences between 32-bit systems and 64-bit systems



32 bit (bit) operating system maximum memory address is 4GB, if you buy the memory bar is 8GB, but the installation is 32-bit operating system, then your operating system can recognize only 4GB of memory, the remaining 4GB memory is wasted, So now more and more people choose to use 64-bit operating system, which is also a big disadvantage of the 32-bit system, 64-bit system with a maximum memory address of 2 64 times, similar to the National Galaxy computer.



10. What is a module?



  The Python module, which is a python file that ends with a. Py, contains Python object definitions and Python statements.



Modules allow you to logically organize your Python code snippets.



Assigning the relevant code to a module will make your code better and easier to understand.



Modules can define functions, classes, and variables, and modules can also contain executable code.



Call Mode:





Import # the module name you want to call, without having a. PY

























2017-10-4 Oldboy python day3


Related Article

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.