Python
An elegant and robust programming language that inherits the power and versatility of traditional compiled languages while also borrowing the ease of use of scripting and interpreted languages.
History of Python Python is a new interpreted scripting language developed by founder Guido van Rossum in Amsterdam during the Christmas season of 1989 as a way to beat the boredom of Christmas. Python was chosen as the name of the programming language because he was a fan of the then popular BBC comedy series "Monty Python".
Guido van Rossum The first Public release of Python, released in 1991, is purely free software, with the source code and interpreter (CPython) under the GNU General Public License (GPL).
Two, Python design ideas Python is designed to be "in line with the habits of the brain", using a minimalist design concept and a uniform and standardized interaction mode. This makes Python easy to learn, understand, and remember. The philosophy of Python developers is "there is one way, and preferably only one way, to do one thing."
Python is a fully object-oriented programming language, and built-in types such as functions, modules, numbers, strings, etc. are all objects. Its classes support advanced OOP concepts such as polymorphism, operator overloading, and multiple inheritance, and Python's unique concise syntax and types make OOP very easy to use. Of course OOP is just an alternative to Python, which, like C++, supports both object-oriented and procedural programming patterns.
Python is an interpreted language, and the current standard implementation of Python is to compile (convert) the statements of the source code into bytecode format, and then interpret the bytecode through the interpreter. Python does not compile the code into the underlying binary code, so Python executes slower than compiled languages such as C and C++. But Python's interpreted language features speed up development while giving it the advantages of an interpreted language that is easy to write and debug.
Python itself is designed to be extensible, and not all features and functions are integrated into the language core. Python provides a wealth of apis and tools to make it easy for programmers to write extension modules in C/C++. Python provides us with a very complete base code base, covering regular expressions, networking, multithreading, GUI, database, and other areas. In addition to the built-in libraries, Python also has a large number of third-party libraries that you can use directly.
The Python compiler itself can also be integrated into other programs that require scripting languages, so many people also use Python as a "glue language", using Python to integrate and encapsulate programs written in other languages. In 2004, Python was used internally at Google. Google Engine writes the performance-demanding parts in C++ and then calls the corresponding modules in Python or Java/Go. Their goal is "Python where we can, C++ where we must", using C++ for hardware manipulation and Python for rapid development.
Note: We can see the design principles of Python by typing the command: import this into any of Python's interactive interpreters. EIBTI is short for "clarity is better than obscurity."
- Advantages of Python
1, high quality software
Python has a concise, clear syntax, and a highly consistent programming pattern. A consistent design style ensures the development of fairly standardized code.
Python provides a "safe and reasonable" exit mechanism for errors. Python supports exception handling, which effectively catches and handles errors that occur while your program is running, allowing you to monitor and handle these errors.
Python code can be packaged into modules and packages for easy management and distribution, which is suitable for collaborative team development.
2, fast development speed
Python is dedicated to the optimization of development speed: concise syntax, dynamic typing, no compilation, rich library support and other features allow programmers to quickly develop projects. Python often takes only a few dozen lines of code to develop features that require hundreds of lines of C code.
The Python parser is easy to debug and test code, and can also be embedded in an application as a programming interface. This makes it possible to debug directly in the development process, avoiding the time-consuming and troublesome compilation process, and greatly improving the speed and efficiency of development.
In Python, since memory management is the responsibility of the Python interpreter, developers are freed from memory management and can focus solely on the application design that is at the top of their development plan. This results in programs written in Python that have fewer errors, are more robust, and have shorter development cycles.
3, powerful
Python is powerful enough and robust enough in itself, and it has many interfaces to other systems, so it is perfectly possible to prototype entire systems using Python.
For more specific tasks, Python comes with a number of pre-coded library tools, from regular expressions to network programming to database programming. In the field of web, data analysis, etc., Python also has powerful frameworks to help you quickly develop your services. For example: Django, TruboGears, Pylons, etc.
4, easy to expand
Python is easily extensible, and (for CPython) can be functionally extended through modules written in C or C++, enabling it to be a flexible bonding language that can script the behavior of other systems and components.
5, Cross-platform
Python is cross-platform. Python can be found on a variety of operating systems (Linux, windows, MacOS, Unix, etc.). Because Python is written in C, and because of C's portability, Python can run on any platform with an ANSI C compiler. Although there are specific modules developed for different platforms, general-purpose software developed in Python on any platform can be modified slightly or run unchanged on other platforms. This portability applies to different architectures as well as different operating systems.
- The disadvantages of Python
The first disadvantage is the slow running speed. Python is very slow compared to C/C++ programs, because Python is an interpreted language, your code will be translated line by line into machine code that the CPU can understand when it is executed, this translation process is very time-consuming, so it is very slow. The C program is compiled directly into the machine code that the CPU can execute before running, so it is very fast. However, according to the 80/20 rule, most programs do not require high speed. In some cases where speed is required, Python designers tend to use JIT techniques, or to rewrite this part of the program in C/C++.
And your own time is a precious resource, more precious than CPU time. The benefits of Python development speed often outweigh the losses of execution speed, especially given the high processing power of modern computers. Some improvements may be too difficult to implement, or may affect the portability or maintainability of the code. Not all performance improvements are worth the effort.
The second disadvantage is that the code cannot be encrypted. If you want to distribute your Python program, you are essentially distributing the source code. This is different from C language, C language does not release the source code, only need to compile the machine code to be released. It is impossible to completely reverse C code from machine code.
5, Python development direction and application scenarios
Web Development:
Python provides a wealth of modules to support sockets programming, multi-threaded programming, can easily and quickly develop network services. Support for the latest XML technology, support for json language, database programming, and Python's ORM framework, making it very convenient to operate the database.
Python also has excellent Django, Tornado, Flask and other web development frameworks, but also with the support of many open source plug-ins, enough to apply to a variety of different web development needs.
Automated operation and maintenance:
Python's built-in interface to operating system services makes it an ideal tool for writing portable administrative tools and widgets that maintain operating systems. Python programs can search files and directory trees, run other programs, and work in parallel with processes and threads.
Web crawler:
In terms of text processing, python provides re module to support regular expressions, but also provides SGML, XML analysis module, many programmers use python for XML program development.
Graphics Processing:
PIL, Tkinter and other graphics library support, can be convenient for graphics processing. For multimedia applications, Python's PyOpenGL module encapsulates the "OpenGL application Programming interface", which can perform two - and three-dimensional image processing. The PyGame module can be used to write game software
In addition, Python is also used in games, artificial intelligence, big data analysis, robotics and other fields.
- Types of Python
Cpython:
Execution process: program ---- (c interpreter) ---- (bytecode) ---- (machine code) -----cpu
The official version of Python, which is Python's original and best-maintained implementation, is written in C. New language features tend to appear here first. The CPython implementation converts the source file (py file) into a bytecode file (pyc file), which is then run on the Python virtual machine.
Jyhton:
Execution process: program ---- (java interpreter) ---- (bytecode) ---- (machine code) -----cpu
The Java implementation of Python, which can be used as a scripting language for Java applications or can be used to create applications using Java class libraries, is also often used to create tests for Java libraries. Jython dynamically compiles Python code into Java bytecode, which is then run on the JVM.
PyPy:
Execution process: program ---- (bytecode) ---- (machine code) -----cpu
A Python implementation written entirely in Python. It supports several advanced features not found in other implementations, such as stackless support and a Just in Time compiler. PyPy converts Python source code into bytecode and then into machine code.
Other categories: Python for.NET, IronPython, RubyPython, Brython...
- Python version
There are two versions of python, python 2.X and python 3:
The last version of python 2.x, Python 2.7 (released in 2010), will officially be supported until 2020.
The first version of python 3.X, python 3.0 (released in 2008)
python 3.X is not compatible with Python 2.X, and Python 2.6 has been officially released as a transition version to Python 3.0, and all versions after 2.6 are transitional versions.
Why build Python 3.X? Because python has developed for more than 20 years, there are many repetitive functions, repetitive modules, and a lot of code has become less concise, so Guido decided to carry out a thorough upgrade, the principle is to simplify, and thus there is a subsequent Python 3.X version.