This article is participating in Python Theme MonthActive link

Python review

Python (pronounced: /ˈpaɪθən/ /ˈpaɪ ɑːn/) is an object-oriented, interpreted computer programming language. It was invented by Dutchman Guido van Rossum in 1989. The first public release was in 1991. Python is pure free software. The source code and interpreter CPython comply with the GNU General Public License (GPL). Python syntax is clean and concise. One of its features is the mandatory indentation of statements with white space.

Python has a rich and powerful library. Often nicknamed the Glue language, it makes it easy to link together various modules made in other languages, especially C/C++. A common application scenario is to use Python to quickly prototype a program (and sometimes even the final interface of the program), and then rewrite the specific parts of the program in a more appropriate language, such as a graphical rendering module in a 3D game. Especially high performance, it can be rewritten in C/C++. It is then wrapped into an extended library that Python can call. It is important to note that you may need to consider platform issues when using extended class libraries, some of which may not provide cross-platform implementations.

In March 2018, the language author announced on the mailing list that Python 2.7 would end support on January 1, 2020. Users who want to continue receiving Python 2.7-related support beyond this date will have to pay a commercial vendor.

Python development

Since its birth in the early 1990s, Python has gradually been widely used in system administration tasks and Web programming.

Python was founded by Guido van Rossum. During Christmas 1989 in Amsterdam, Guido decided to develop a new script interpreter as a successor to the ABC language in order to overcome the Christmas boredom. He chose Python (boa constrictor) as the name of the programming language because he was a fan of a comedy group called Monty Python.

ABC is a teaching language designed by Guido. In Guido’s opinion, ABC is a beautiful and powerful language designed specifically for non-professional programmers. However, ABC language did not succeed. Guido believes that the reason is that ABC language is not open. Guido is determined to avoid this error in Python. At the same time, he wanted to achieve something that had been flashed but never achieved in ABC. And so Python was born in Guido’s hands. It can be said that Python grew out of ABC, largely influenced by Modula-3 (another rather elegant and powerful language designed for small communities). And it combines the conventions of the Unix shell and C.

Python has become one of the most popular programming languages. In January 2011, it was named language of the Year 2010 by TIOBE Programming Language Rankings. Python usage has grown linearly since 2004.

Due to the simplicity, readability and expansibility of Python, there are more and more research institutions using Python to do scientific calculation in foreign countries. Some well-known universities have adopted Python to teach programming courses. For example, Fundamentals of programming at Carnegie Mellon University and Computer Science and Introduction to Programming at MIT are taught in Python. Many open source scientific computing software packages provide Python call interfaces, such as the well-known computer vision library OpenCV, three-dimensional visualization library VTK, and medical image processing library ITK. For example, the following three very classic scientific computing extension libraries: NumPy, SciPy, and Matplotlib provide Python with fast array processing, numerical computation, and graphing capabilities, respectively. The Python language and its many extension libraries are therefore ideal for engineering, researchers working with experimental data, charting, and even developing scientific computing applications.

Python positioning

Python’s design philosophy is “elegant,” “clear,” and “simple.” As a result, the Perl concept of “there are always more than one way to do the same thing” is often intolerable among Python developers. The Philosophy of Python developers is “one way, preferably only one way, to do one thing”. Faced with multiple choices when designing the Python language, Python developers generally reject fancy syntax in favor of explicit syntax with little or no ambiguity. Because of this difference in design philosophy, Python source code is generally considered more readable than Perl and can support large-scale software development. These guidelines are known as Python aphorisms. To get the complete list, run import this inside the Python interpreter.

Python developers try to avoid immature or unimportant optimizations. Some speed up patches for non-critical parts are not usually incorporated into Python. So many people think Python is slow. However, according to the 80/20 law, most programs do not require much speed. In some cases where speed is critical, Python designers tend to use JIT techniques, or rewrite parts of the program in C/C++. The JIT technology available is PyPy.

Python is a fully object-oriented language. Functions, modules, numbers, and strings are all objects. And fully support inheritance, overload, derivation, multiple inheritance, is beneficial to enhance the reuse of source code. Python supports overloaded operators and dynamic typing. In contrast to Lisp, a traditional functional programming language, Python provides limited support for functional design. Two Standard libraries (Functools, itertools) provide proven functional programming tools from Haskell and Standard ML.

Although Python may be roughly classified as a “script language,” it is also widely used by Google for large-scale software development projects such as Zope, Mnet, and BitTorrent. Python supporters prefer to call it a high-level dynamic programming language because “scripting languages” generally refer to languages that do only simple programming tasks, such as ShellScript and VBScript, and are not comparable to Python.

Python itself is designed to be extensible. Not all features and functions are integrated into the language core. Python provides a rich API and tools that make it easy for programmers to write extension modules using C, C++, and Cython. The Python compiler itself can also be integrated into other programs that require scripting languages. As a result, many people also use Python as a “glue language.” Use Python to integrate and encapsulate programs written in other languages. Many projects within Google, such as Google Engine, write high-performance parts in C++ and then call the corresponding modules in Python or Java/Go. Alex Martelli, author of the Python Technical Manual, said: “It’s hard to say, but Python was in use internally at Google in 2004, and Google recruited a lot of Python gurus, but decided to use Python before that, Their purpose is Python where we can, C++ where we must, C++ for hardware manipulation, Python for rapid development.”

Python running

When Python is executed, the source code in the. Py file is first compiled into Python byte code, which is then executed by the Python Virtual Machine (Python Virtual Machine). The basic idea of this mechanism is consistent with Java and.NET. However, Python Virtual Machine works with Java or. NET Virtual Machine is different, Python Virtual Machine is a more advanced Virtual Machine. Advanced here is not advanced in the usual sense, not that Virtual Machine Python is superior to Java or. NET is more powerful than Java or. NET, Python’s Virtual Machine is further removed from the real Machine. In other words, Python’s Virtual Machine is a Virtual Machine of a higher level of abstraction. A bytecode file compiled by C-based Python, usually in. Pyc format. In addition, Python can be run in interactive mode. For example, major operating systems such as Unix/Linux, Mac, and Windows can run the Python interactive environment directly in command mode. Direct instruction can realize interactive operation.

Python advantages

  • Simplicity: Python is a language that stands for the idea of simplicity. Reading a good Python program feels like reading English. It allows you to focus on solving problems rather than figuring out the language itself.
  • Easy to learn: Python is extremely easy to learn because Python has extremely simple documentation.
  • Fast: Python’s underlying language is written in C, and many standard and third-party libraries are also written in C, which is very fast.
  • Free, open source: Python is one of FLOSS (free/open source software). Users are free to distribute copies of the software, read its source code, make changes to it, and use parts of it in new free software. FLOSS is based on the concept of a community sharing knowledge.
  • High level language: Programming in Python does not need to worry about low-level details such as how to manage the memory your program uses.
  • Portability: Due to its open source nature, Python has been ported to many platforms (with modifications to make it work on different platforms). These platforms include Linux, Windows, FreeBSD, Macintosh, Solaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, Z /OS, Palm OS, QNX, VMS, Psion, Acom RISC OS, VxWorks, PlayStation, Sharp Zaurus, Windows CE, PocketPC, Symbian and Google’s Linux-based Android platform.
  • Interpretability: A program written in a compiled language such as C or C++ can be converted from a source file (C or C++) to a language your computer uses (binary code, 0 and 1). This process is done using the compiler and various tags and options.
  • When running the program, the link/reprinter software copies your program from hard disk to memory and runs it. Programs written in Python do not need to be compiled into binary code. You can run programs directly from source code. Inside the computer, the Python interpreter converts the source code into an intermediate form called bytecode, which is then translated and run into the machine language the computer uses. This makes Python much easier to use. It also makes Python programs more portable.
  • Object-oriented: Python supports both procedural and object-oriented programming. In a “procedural oriented” language, programs are built from procedures or simply functions of reusable code. In “object-oriented” languages, programs are built from objects composed of data and functions.
  • Extensibility: If you need a critical piece of code to run faster or you want to keep some algorithms private, you can write parts of your program in C or C++ and use them in Python programs.
  • Embeddability: Python can be embedded in C/C++ programs to provide scripting functionality to program users.
  • Rich libraries: The Python standard library is really huge. It can help with a variety of jobs, including regular expressions, document generation, unit testing, threading, databases, Web browsers, CGI, FTP, E-mail, XML, XML-RPC, HTML, WAV files, password systems, GUIs (graphical user interfaces), Tk, and other system-related operations. This is called Python’s “full-featured” idea. In addition to the standard library, there are many other high-quality libraries, such as the wxPython, Twisted, and Python image libraries, to name a few.
  • Regular code: Python uses forced indentation to make code readable. Programs written in Python do not need to be compiled into binary code.

Python shortcomings

  • Single line statements and command line output problems: Many times programs cannot be concatenated on a single line, such as import sys; For I in sys.path:print I. Perl and AWk do not have this limitation and can easily write simple programs in the shell without having to write them to a.py file, as Python does.
  • Unique syntax: This probably shouldn’t be called a limitation, but the way it indents statements can confuse many beginners. Even experienced Python programmers can fall into this trap.
  • Slow: compared to C and C++.

Python application

  • System Programming: provides API (Application Programming Interface), can facilitate system maintenance and management, One of the symbolic languages under Linux, is the ideal Programming tool for many system administrators.
  • Graphics processing: PIL, Tkinter graphics library support, can facilitate graphics processing.
  • Mathematical processing: The NumPy extension provides extensive interfaces to many standard mathematical libraries.
  • Text processing: Python provides re modules that support regular expressions. It also provides SGML and XML analysis modules. Many programmers use Python to develop XML programs.
  • Database programming: Programmers can communicate with Microsoft SQL Server, Oracle, Sybase, DB2, MySQL, SQLite and other databases through modules that follow the Python DB-API specification. Python comes with a Gadfly module that provides a complete SQL environment.
  • Network programming: provide rich module support Sockets programming, can easily and quickly develop distributed applications. It is widely used by large-scale software development projects such as Zope, Mnet and BitTorrent. Google.
  • Web programming: Application development language that supports the latest XML technology.
  • Multimedia applications: Python’s PyOpenGL module encapsulates the “OpenGL Application Programming Interface” for 2d and 3D image processing. The PyGame module can be used to write game software.
  • Pymo engine: Pymo is an AVG game engine running on Symbian S60V3,Symbian3,S60V5, Symbian3, Android. It is named PYMO because it is developed on python2.0 and is suitable for creating AVG games in the memories off style.
  • Hacker Programming: Python has a library of hacks, built in with functions you are familiar with or unfamiliar with, but lacking in fulfillment.
  • Write a simple crawler in Python: First, get the corresponding HTML source from the urllib2 Module. (PS: urllib2 is deprecated after Python3.3, replaced by urllib), you can store the source URL in the content variable, which is of type character. The next step is to extract what we need from this heap of HTML source code. Take a look at the code for the content in Chrome (or Firebug in Firefox). You can see that the URL information is stored in the SPAN tag, which can be retrieved using the regular expression.
  • Python is now widely used in artificial intelligence, which is what has made Python so popular in recent years.

This document was compiled and summarized on June 14, 2018. If there is any conflict with the current version, the introduction of the current version shall prevail. This article is for reference only. Welcome to study and exchange!