A brief introduction to Python (detailed explanation with pictures and text)

WBOY
Release: 2022-03-24 19:05:31
forward
3945 people have browsed it

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.

A brief introduction to Python (detailed explanation with pictures and text)

Recommended learning: python learning tutorial

1. Computer composition

 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:

A brief introduction to Python (detailed explanation with pictures and text)

1.1 Hardware system

 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:

A brief introduction to Python (detailed explanation with pictures and text)
  • Operator: Responsible for arithmetic operations and logical operations of data, that is, data processing;
  • Controller: The central nervous system of the computer, coordinating the work of various components of the computer and the access to memory and peripherals;
    Among them: The arithmetic unit and controller are collectively called the central processing unit, that is, CPU
  • Memory: A component that implements the memory function, used to store information such as programs, data, commands, and various signals, and provide this information when needed;
  • Input device: Realizes the input of programs, original data, text, characters, control commands or data collected on site into the computer;
  • Output device: Realizes the output of intermediate results or final results generated by computer processing, including various data symbols, text, control signals and other information;

1.2 Software system

 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:

A brief introduction to Python (detailed explanation with pictures and text)
  • System software: Ensures the normal operation and performance of computer hardware, and provides computer users with an intuitive, friendly and convenient interface.
  1. Operating system: System software that facilitates users to control and manage computer software and hardware resources. It has complex functions and is the foundation and core for the normal operation of all software;
  2. Compiler: Also called a language processing program, its function is to translate programs written by programmers using various programming languages, such as Java and Python, into computer-executable machine language.
  • Application software: Application software is that part of software provided by computers to meet the needs of different users. It can broaden the application fields of computer systems and method hardware. performance.
  1. ## Social office categories: WeChat, QQ, WPS, Tencent Conference, DingTalk, Momo, etc.;
  2. Leisure and entertainment categories : QQ Music, Tencent Video, Steam, Happy Landlords, etc.;
2. Program operation mechanism

  Machine 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.

2.1 Compiled and interpreted type

Analysis: Can the computer directly recognize the following Python code?

"""
分析:在控制台输出以下Python代码,计算机可以直接处理吗?
"""print("Hello world!")  # print()为Python中的内置函数,主要用于输出括号内的内容,类似于Java中的System.out.println("Hello world!")
Copy after login
Obviously, the above code mainly consists of English letters and punctuation marks, but as mentioned before, the computer can only recognize machine codes (0 and 1), that is, it does not recognize this code at all.

A brief introduction to Python (detailed explanation with pictures and text)
 So, how do we control the computer to work through code?

A brief introduction to Python (detailed explanation with pictures and text)
 The process of human-computer interaction is like Just like when a local communicates with a foreigner, if both parties want to understand each other's ideas, they need an intermediary that can somehow convert the other person's language into a language they can understand, and vice versa. Therefore, if the computer wants to understand the code we write, it needs to convert it into machine code that it can recognize. According to the conversion process, programming languages ​​are divided into compiled and interpreted.

  • Compiled type: Compiled language can directly convert the code into machine code that the computer can recognize and execute, such as C .
A brief introduction to Python (detailed explanation with pictures and text)
  • Interpreted: Interpreted languages ​​first convert the code into bytecode and then translate it into computer-readable Recognized machine code, such as Python.
A brief introduction to Python (detailed explanation with pictures and text)

2.2 The process of computer processing program

  1. The user opens the program and the program starts executing;
  2. The operating system will The program content and related data are sent into the computer memory;
  3. CPU reads instructions from memory according to the program content;
  4. CPU analyzes and processes instructions, and prepares for the next instruction;
  5. Read the next instruction, analyze and process it, and repeat this cycle until all instructions in the program are processed, and finally put the calculation result into the memory address specified by the instruction;

2.3 Computer Language History of Development

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".

A brief introduction to Python (detailed explanation with pictures and text)
  • Machine language: Equivalent to the primitive stage of human beings;

 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.

  • Assembly language: Equivalent to the stage of human handicraft industry;

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.

  • High-level programming language: Equivalent to the human industrial stage;

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:
A brief introduction to Python (detailed explanation with pictures and text)

3. Python language History of birth and development

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:

A brief introduction to Python (detailed explanation with pictures and text)
##3.1 Birth and Development

  • Era background: Hardware limitations;
The author of Python,

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: The essence is to call commands, it is not a real language;
This programming method makes Ji Feel more distressed. Guido knows how to write a function in C language, but the entire writing process takes a lot of time, even though he already knows exactly how to implement it. His other option is

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.

  • ABC language: Readable and easy to use, with obvious disadvantages;
##  Guido hopes to have a language that can be like Like

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:

  1. Poor scalability: ABC is not a modular language. If you want to add functionality to it, such as Graphical support requires many changes.
  2. Cannot be performed directlyIO: 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?
  3. Excessive innovation: ABC expresses the meaning of the program in the form of natural language. For example, it uses How to to define a function, while for programmers, they are more accustomed to using function or define.
  4. Difficulty in dissemination: The ABC compiler is very large and must be saved on a tape, which means that if you want to use it, you must first prepare a large tape.
  • Python gestation and growth: It is easy to learn and has comprehensive functions between C 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:
  • Between C and shell, a language with comprehensive functions, easy to learn and use, and scalable
. As a language design enthusiast, Guido has already tried to design languages. This time, it was nothing more than a pure act of hacking.

 # ##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 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.

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.

3.2 Design philosophy

  • Get Python design philosophy: After successfully installing the Python software (next topic), open any editing environment and type import thisRun it;
A brief introduction to Python (detailed explanation with pictures and text)
  • ##Summary: Simple, elegant, scalable, practical and flat is the key, the best solution is only one???
3.3 Advantages and Disadvantages

  • Advantages:
  1. Easy to learn and expandable: Reading a good Python program is like appreciating a beautiful article, although its requirements are very strict, such as forcing indentation to improve the readability of the code sex. The pseudocode nature of Python allows us to focus more on the logic of solving problems rather than understanding the language itself. For example, we do not need to pay too much attention to low-level details such as memory management. If we want a critical code to run faster (C is more than 50 times faster than Python) or we want certain algorithms not to be made public, we can use C## for part of the program #Or C language, and then call it in the Python program.
  2. Free open source and portable:
  3. Python is one of FLOSS (free/open source software), which means we can freely distribute copies and read of this software its source code, make changes to it, and use parts of it in new free software. Due to its open source nature, Python is portable on many computer platforms, such as Windows, Linux, etc..
  4. Object-oriented:
  5. Python supports both procedural and object-oriented programming. In "procedural-oriented" languages, programs are built from procedures or functions that are simply reusable code. In "object-oriented" languages, programs are constructed from objects composed of data and functions. Compared with other programming languages ​​such as C and Java, Python implements object-oriented programming in a very powerful and simple way, and its three major features of encapsulation, inheritance and polymorphism are the keys to its "god".
  6. Dynamic language:
  7. Dynamic language, also known as Weakly typed language, means that when a variable is created, does not need to declare the type, the specific type It is determined based on the data type in the memory unit pointed to, that is, whatever type is pointed to is the type. On the contrary, static language (strongly typed language), when defining a variable,needs to declare the type, and the data type that can be stored in the memory unit pointed to by the variable is fixed. For example, an integer variable is defined in Python as num = 10, but in Java it is 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.
  8. Interpreted language:
  9. Compiled language, such as a program written in C 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.
  10. Rich libraries:
  11. Including Python’s own standard library and third-party libraries. Among them, Python's standard library can help us handle various tasks, including regular expressions, document generation, threads, databases, HTML, GUI, etc. This is calledPython's "full-featured" philosophy. In addition to the standard library, Python also supports the installation of third-party libraries, such as wxPython, Twisted, and Python image libraries.
    Disadvantages:
  • The Python language is very perfect, with no obvious shortcomings and shortcomings. The only shortcoming is slow execution efficiency, which is common to interpreted languages, but this defect will be weakened as the performance of computer hardware continues to improve.
  • 3.4 Application scenarios

A brief introduction to Python (detailed explanation with pictures and text) Recommended learning:
python tutorial

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!