This article brings you relevant knowledge about python, which mainly introduces related issues including the program operating mechanism and the birth and development history of the Python language. I hope it will be helpful to everyone.
Recommended learning: python learning tutorial
Computer It has become the core device of our time and we need it all the time. It is no longer the desktop and server that people think of. It has evolved into any object around us, such as mobile phones, tablets and laptops. Many people are not aware of it subjectively, but the actual device does contain a "computer". Equipment, such as televisions, microwave ovens, cars, and even smart robots for children to play with. It is no exaggeration to say that computers have become an extension of the human body, an extension of the brain, and an indispensable part. In the future, computers will really enter the human body, enter the brain, and truly become a part of the human body. For example, the protagonist in the science fiction movie "The Matrix" can learn quickly after having a super needle inserted into his neck, change the brain's neural network, and become a kung fu master in seconds. Computer, commonly known as computer, is an electronic machine used for high-speed calculations. It is one of the greatest scientific and technological inventions of the 20th century. It can perform numeric calculations and logical judgments, and also has storage memory and data processing functions. A complete computer system consists of hardware system and software system, as shown in the following figure:
Hardware system can be mainly divided into host and peripherals, which refers to the physical entities that constitute the computer system. They are mainly composed of various electronic devices and electromechanical devices. . From ENIAC
(the world's first computer) to the most advanced computers at present, the design of hardware systems adopts the von Neumann
architecture, as shown below:
CPU
Software system It can be mainly divided into system software and application software, which refers to various programs required to ensure the normal operation of the computer. It is the main object of our programming practice and is composed as follows:
2.1 Compiled and interpreted typeMachine language is also called machine code. It is a set of instructions that can be analyzed and executed by CPU
. The computer can only recognize the
machine code of 0 and 1, and cannot accept human languages similar to Chinese, English or other languages. Therefore, in order to realize the interaction between humans and computers, various programming languages have emerged, such as C, Java, PhP, and Python.
Analysis: Can the computer directly recognize the following Python code?
""" 分析:在控制台输出以下Python代码,计算机可以直接处理吗? """print("Hello world!") # print()为Python中的内置函数,主要用于输出括号内的内容,类似于Java中的System.out.println("Hello world!")
C
. Python
. Algorithms are the soul of computers, and programming languages are the tools that make computers have souls. With the development of computer hardware, computer programming languages have also evolved from low-level to high-level, and the core idea of each change is to "make it easier for people to program." The faster, smaller, and lower the cost of computer hardware, the more scenarios it will be applied to in human society, and the more complex the algorithms required will be, requiring more advanced computer programming languages. The ENIAC, which initially weighed tens of tons but could only perform 5,000 calculations per second, could only be used for very small applications, such as ballistic calculations. Today, the computing power of any one person's mobile phone can instantly surpass the combined computing power of all the computers on the earth at that time. The easier a language is to use, the more people use it; the more people use it, the more people can collaborate; the more people collaborate, the more complex objects can be created. In modern society, it is possible for dozens, hundreds, or even thousands of people to collaborate on a piece of software, which naturally provides a "human basis" for the development of complex software. This is a common social phenomenon among humans. The easier a tool is to use, the more it is used, and the collaboration of a large number of people, it can completely change an industry or even human society. The next thirty years will definitely be a world of software talents. In addition to ordinary software, a large number of artificial intelligence software, such as autonomous driving, robot nannies and robot girlfriends, will enter our lives. Computer technology and genetic engineering will even be combined to achieve immortality. Interested You can read "A Brief History of the Future: From Homo Sapiens to Sapiens".
Machine language consists of numbers instruction. When you are asked to use digital programming and write hundreds or even thousands of numbers, and face pure numbers every day, you can boldly predict: "100% of programmers will have mental problems." Machine language, which typically consists of strings of numbers (eventually reduced to binary 0s and 1s), is too cumbersome for humans to understand. Using machine language, humans cannot program complex programs.
In order to facilitate programming and solve more complex problems, programmers began to improve Machine language uses abbreviated mnemonics (words) to represent basic computer operations. These mnemonics form the basis of assembly language, such as LOAD, MOVE
, etc., which make it easier for people to remember and use. It feels much better to recognize hundreds or thousands of words than hundreds or thousands of numbers. Assembly language is equivalent to human handicraft society, which requires extremely skilled craftsmen, but the development efficiency is also very low. Although assembly language can write efficient programs, it is not easy to learn and use, and it is difficult to debug. Another complex issue, assembly language and early computer languages (Basic, Fortran, etc.)
did not consider structured design principles, but used goto statements
as program flow The main method of controlling . The consequence of this is that a mess of transposition statements makes the program almost impossible to read. For programmers of that era, it became a challenge to be able to understand the code they wrote last month. Even so, assembly language is still used in the field of industrial electronic programming, software encryption and decryption, computer virus analysis, etc.
For simple tasks, assembly language can do the job. However, with the development of computers and their gradual penetration into all aspects of work and life, some complex tasks have emerged, and assembly language has become insufficient (it should be said that programmers use assembly language to solve complex problems and there is a bottleneck). As a result, high-level languages appeared, such as C
, Java
, etc. The more advanced the language, the closer it is to human thinking, and the easier it is to use. High-level languages, especially object-oriented languages, such as Java, Python
, etc., make programming more and more difficult and lower. At present and for the foreseeable future, computer languages are still in the "third generation high-level language" stage. High-level languages allow programmers to write programs using instructions that are close to everyday English. For example, to implement a simple task: A B=C
, the implementation using machine language, assembly language and high-level language is as follows:
Python is a dynamic data type, object-oriented interpreted language, mainly used in various fields of artificial intelligence, such as machine learning, crawlers and data analysis, depth learning, computer vision, etc.
TIOBE Programming Language Ranking:
Guido von Rossum (Guido von Rossum Tom), Dutch. In 1982, Guido received a master's degree in mathematics and computing from the University of Amsterdam. However, although he was a mathematician of sorts, he enjoyed computers even more. In his words, although he has dual qualifications in mathematics and computers, he always tends to do computer-related work and is keen on doing anything related to programming. At that time, Guido came into contact with and used languages such as Pascal, C, and Fortran. The basic design principle of these languages is to make machines run faster. In the 1980s, although IBM and Apple had launched a wave of personal computers, these personal computers had very low configurations. For example, the early Macintosh only had an 8MHz CPU frequency and 128KB of RAM. A large array could fill up the memory.
The core of all compilers is to optimize so that the program can run. In order to increase efficiency, the language also forces programmers to think like a computer so that they can write programs that are more in line with the taste of the machine. In that era, programmers were eager to squeeze every inch of computer power with their hands. Some people even think that C language pointers are a waste of memory. As for dynamic typing, automatic memory management, object-oriented... Don't think about it, it will paralyze your computer.
shell. Bourne Shell has existed as an interpreter for
UNIX systems for a long time. UNIX administrators often use shell to write some simple scripts to perform some system maintenance work, such as regular backup, file system management, etc.
Shell can be like glue, connecting many functions under the UNIX system together. Many C language programs with hundreds of lines can be completed in just a few lines under the shell. However, the essence of the shell is to call commands, it is not a real language. For example, the shell does not have numeric data types, and addition operations are very complicated. In short, the shell cannot fully mobilize the computer's functions.
C language, it can fully call the functional interface of the computer, and like shell, it can be easily programmed. ABC language gives Guido hope. ABC was developed by the Institute of Mathematics and Computing in the Netherlands. Guido worked at the institute and was involved in the development of the ABC language. ABC language is for teaching purposes. Unlike most languages at the time, the goal of ABC language was to "make users feel better". ABC Language hopes to make the language easy to read, use, remember and learn, and to stimulate people's interest in learning programming. However, the ABC language compiler requires very high computer configuration to run, and the users of these computers are usually proficient in computers, so they pay more attention to the efficiency of the program rather than its learning difficulty. On the other hand, the following fatal design problems are the reason why it has not become popular:
:
ABC cannot directly operate the file system, that is, it cannot directly read and write data. Difficulties in input and output are fatal to computers. Can you imagine a sports car that cannot open the door?
to define a function, while for programmers, they are more accustomed to using
function or
define.
and
Shell In 1989, in order to pass the Christmas vacation, Guido began to write a compiler for the Python language. The name Python comes from Guido’s beloved TV series
Monty Python’s Flying Circus. He hopes that this new language called Python can meet his ideals: # ##In 1991, the first Python compiler was born. It is implemented in C language and can call C language library files. From its birth, Python has had: classes, functions, exception handling, core data types including tables and dictionaries, and a module-based expansion system. A lot of Python syntax comes from C, but it is also strongly influenced by the ABC language. Some rules from the ABC language are still controversial to this day, such as forcing indentation , but these grammatical rules make Python easy to read. On the other hand, Python smartly chooses to obey some conventions, especially those of the C language, such as restoring the equal sign assignment . Guido believes that if something is established based on "common sense", there is no need to get too hung up on it. Python has paid special attention to
scalability from the beginning. Python can be expanded on multiple levels. From a high level, you can directly import the .py file. Under the hood, you can reference C libraries. Python programmers can quickly use Python to write .py files as expansion modules. But when performance is an important factor to consider, Python programmers can go deep into the bottom layer, write C programs, compile them into .so files and introduce them into Python for use. Python is like building a house with steel. A large framework is defined first, and programmers can expand or change it quite freely within this framework. The original Python was developed entirely by Guido himself. Python is welcomed by Guido's colleagues. They provide quick feedback and participate in Python improvements. Guido and some colleagues form the core team of Python. They spend most of their spare time hacking Python. Subsequently, Python expanded beyond the institute. Python hides many technical details and leaves them to the compiler to handle, and highlights logical programming thinking. Therefore, Python programmers can spend more time thinking about the logic of the program instead of specific implementation details. This feature attracted a large number of programmers, and Python became popular. Computer hardware is becoming more and more powerful, and Python is easy to use, so many people are turning to Python. Guido maintains a mail list, and Python users communicate through email. Python users come from many fields, have different backgrounds, and have different needs for Python. Python is quite open and easy to expand, so when users are not satisfied with the existing functions, it is easy to expand or transform Python. These users then send their changes to Guido, who decides whether to add the new features to Python or the standard library. It would be a great honor if the code could be incorporated into Python itself or the standard library. Because of Guido's supreme decision-making power, he was called The power of Python and its standard library is the result of contributions from the entire community. Python developers come from different fields, and they bring the advantages of different fields to Python. For example, regular expressions in the Python standard library refer to Perl, while functions such as lambda, map, filter, and reduce refer to Lisp. Some features of Python itself and most of the standard library come from the community. The Python community continues to expand and has its own newsgroup, website, and fund. Starting from Python 2.0, Python has also changed from a mail list development method to a completely open source development method. A community atmosphere has been formed, work is shared by the entire community, and Python has also achieved faster development. As of today, the framework of Python has been established. The Python language organizes code with objects as the core, supports multiple programming paradigms, uses dynamic types, and automatically performs memory recycling. Python supports interpreted execution and can call C libraries for expansion. Python has a powerful standard library. Since the standard library system has stabilized, the Python ecosystem has begun to expand to third-party packages. These packages, such as Django, web.py, wxpython, numpy, matplotlib, and PIL, upgrade Python into a species-rich tropical rainforest. Python advocates elegance, clarity, and simplicity. It is an excellent and widely used language. Python ranks eighth in the TIOBE rankings. It is Google's third largest development language, Dropbox's basic language, and Douban's server language. The development history of Python can be used as a representative and bring us many enlightenments. In the development process of Python, the community plays an important role. Guido thinks that he is not an all-round programmer, so he is only responsible for formulating the framework. If the problem is too complicated, he will choose to go around it, that is, cut the corner. These problems are ultimately solved by others in the community. The talents in the community are extremely rich. Even things that are slightly distant from development, such as creating websites and raising funds, there are people who are willing to handle them. Today's project development is becoming more and more complex and larger. Cooperation and an open mind will become the key to the ultimate success of the project. Python has learned a lot from other languages, whether it is ABC that has entered history, or C and Perl that are still in use, and many other languages not listed. It can be said that The success of Python represents the success of all the languages it draws from. Similarly, Ruby borrows from Python, and its success also represents the success of Python in some aspects. Every language is a mixture, it has its advantages, but it also has various flaws. At the same time, the judgment of "good or bad" of a language is often subject to external factors such as platform, hardware, era, etc. Programmers have experienced many language disputes. "the lifelong benevolent dictator"
. On July 12, 2018, after completing PEP (Python Enhancement Proposals) 572, Guido decided to withdraw from the core decision-making level of Python. 3.2 Design philosophy
import this
Run it;
3.3 Advantages and Disadvantages
C
language, and then call it in the Python program.
int num = 10;
. Summary: Dynamic types point to variables, and the contents in the memory unit are immutable; static types point to immutable, and the contents are variable.
can be converted from a source file (C language) to A language that your computer uses, which is binary code (0s and 1s)
. This process is done through the compiler and different flags and options. When we run the program, the connection reprinter software copies our program from the hard disk to the memory and runs it. Programs written in Python language do not need to be compiled into binary code. We can run the program directly from the source code. Inside the computer, the Python interpreter converts source code into an intermediate form called bytecode, which is then translated into machine code used by the computer and run. Since we only need to copy our Python program to another computer for it to work, this also makes Python programs easier to port.
Disadvantages:
The above is the detailed content of A brief introduction to Python (detailed explanation with pictures and text). For more information, please follow other related articles on the PHP Chinese website!