Introduction and development history of Python

Python, pronounced ['paɪθɑn], is translated into Chinese as python, and the Python logo also looks like two intertwined pythons. However, the Python language and pythons actually have nothing to do with each other.

Python's slogan is: "Life is short, I use Python!". This slogan has been widely used in the Python industry and has almost become an advertising slogan.

The Python language was independently developed and completed the first version by the Dutch programmer Guido van Rossum, known as "Uncle Turtle" in the world. "Uncle Turtle" once worked for Google and currently works for Dropbox. During the Christmas period of 1989 in Amsterdam, in order to kill the boredom of Christmas, he decided to develop a new script interpretation language as an inheritance of the ABC language. Then he did it and realized it (the ability of a great god). The reason why he chose Python as the name of the programming language was because he was a fan of a comedy group called Monty Python. His original intention was not to choose a python.

The first public release of Python was released in 1991, so this year is regarded as the birth year of Python.

Python source code follows the GPL (GNU General Public License) agreement, which is an open source agreement, which means you can use and distribute it for free without worrying about copyright issues.

Python is currently maintained by a core development team. Uncle Gui belongs to the position of Supreme Emperor and still plays a vital role in guiding its progress.

1. Development Trend of Python

Please add image description

From the picture above, we can see that Python has experienced explosive development in the past three years. The picture below is the TIOBE global programming language popularity ranking in July 2017. From it we can see that Python has squeezed out C# and has firmly entered the fourth place. It is the well-deserved leader of interpreted languages.
Please add image description

We mentioned earlier that Python was born in 1991, which means it is 26 years old, which is 4 years earlier than the JAVA language in 1995. Why is it a late bloomer and only now making efforts?

First, in the 1990s, computer performance was much worse than it is now. Program execution speed and efficiency were very important. Rapid development was not the first priority, but machine performance was. As an interpreted dynamic language, Python is inherently slow in its interpretation method. Therefore, it was not favored by the programming community at the time. Its core concepts of pursuing development speed, emphasizing simplicity and elegance, and lowering the programming threshold were somewhat ahead of its time. mainstream. Today, computer hardware performance has been improved by orders of magnitude. Computing power is no longer the most important factor limiting programming languages. Agile development has become an important factor in language selection in production environments. Python satisfies this very well. , resulting in rapid development.

Second, Python was not born well. In contrast, JAVA comes from a well-known family. Its owner is SUN. At that time, the number one company on the Internet was similar to Google's current status. Therefore, it was vigorously promoted and had a group of capable, dedicated, and organized teams to develop and maintain it, so it quickly gained popularity. It was successful, became popular, and still occupies the top position of programming languages. Python was written by an individual. He came from a poor family. Uncle Gui didn’t have a lot of skills, and his personal time and energy were limited. Although there were some volunteers to help with some things, there was no doubt that compared with the regular JAVA army, the energy was still much lower. All of this resulted in Python's slow development in the early stages, and even now it has not solved its criticized GIL problem.

2. Characteristics of Python language

1. Simple and easy to learn, clear and elegant, fast development speed

**Simple and easy to learn:** Compared with C and Java, Python’s learning cost and difficulty curve are not lower, and it is more suitable for novices to get started and the bottom-up technical climbing route. Set a small goal to climb a small mountain first, and then move on to higher mountains. Unlike C and JAVA light language learning itself, for many people it is as unattainable as Mount Everest.
**Clear and elegant: Python's syntax is very concise, the amount of code is small, and it is very easy to write. It is also very easy to test, refactor, and maintain the code. A small script may require 1,000 lines in C and hundreds of lines in JAVA, but it often only takes dozens of lines in Python!
****Fast development speed:****What is the lifeline of current Internet companies? Product development speed! If your development speed is not fast enough, other people's products will have been launched before your product is launched, and you will have no room to survive. There are countless real examples here. So, if Python’s development speed is said to be second, no one dares to call it first! (Debate is not welcome_ )

2. Cross-platform, portable, extensible, interactive, interpreted, object-oriented dynamic language

Cross-platform: Python supports mainstream operating systems such as Windows, Linux and MAC os.
Portable: Code can usually be ported to other platforms without much change.
Extensible: The Python language itself is written in C language. You can embed C in Python to improve the running speed and efficiency of the code. You can also rewrite any module of Python in C language, fundamentally rewriting Python, which is what PyPy does.
Interactive: Python provides good human-computer interaction interfaces, such as IDLE and IPython. You can enter and execute code from the terminal and get results, interactive testing and debugging code snippets.
Interpreted: The Python language is analyzed line by line by the interpreter during execution, runs line by line and outputs the results.
Object-oriented: The Python language has all object-oriented features and functions and supports class-based program development.
Dynamic language: its structure can be changed at runtime. For example, new functions, objects, and even codes can be introduced, existing functions can be deleted or other structural changes can be made. Dynamic languages ​​are very dynamic.

3. "Built-in battery", a large number of standard libraries and third-party libraries

Python provides us with a very complete basic library, covering all aspects of system, network, file, GUI, database, text processing, etc. These are installed by default along with the interpreter and are common to all platforms. You do not need to install third-party support. Complete most tasks, this feature is known as "batteries included".

In the programmer world, there is a saying called "Don't reinvent the wheel." What does that mean? That is to say, don’t do repeated development work. If there is already an open source solution or third-party library for a certain problem, don’t develop it yourself, just use someone else’s. Don’t be too superstitious about your coding abilities. You must know that being built into Python as a standard library must have reached the highest level in terms of reliability and algorithm efficiency. Third-party libraries that can be widely used must have withstood a large number of application tests. . Unless the company requires it, don't develop it yourself. Please use ready-made libraries. Let the world's top programmers do the work of making wheels. Without extreme thinking and mathematical abilities, it is difficult to create useful wheels.

4. The community is active with many contributors and they help each other.

The existence of the technical community is equivalent to the compass in the hands of programmers. Without a compass, many times, when encountering a problem, it is like a headless fly that can only fly around and eventually faint and die in the vast ocean. The technical community can provide us with great help in learning and using language. Whether it is early learning or future work, as long as we have problems, the experts in the technical community can help us solve them. With these help, we can help us better Understand, learn and use a language well. The technical community also promotes the development direction and functional requirements of the Python language, prompting companies to use the Python language more and recruit Python programmers.

However, however, the above mentioned is abroad. In China, there seems to be no relatively mature Python technical community with a wide range of influence. Or is it just that I have limited knowledge and don’t know? According to my analysis, there are historical reasons and habits formed during the popularity of Python. Foreign Python masters like to communicate through mailing lists, wikis, etc., while domestic forums, bbs, etc. have not formed a large scale, so the current situation has been caused. .

Therefore, students, learn English well and communicate with programmers around the world!

5. Open source language has huge development momentum

Python is written based on C language and uses the GPL open source license. You can obtain its source code for free for learning, research and even improvement. When everyone adds fuel to the fire, more people participate in the development of Python, which promotes its better development and more applications, forming a virtuous cycle. The reason why Python is becoming more and more popular is because of its openness and freedom, which has gathered popularity and formed a community. Many people contribute to it, and more and more people use it, which naturally increases its market share. Enterprises, companies, and manufacturers have to use Python, and more and more Python programmer positions are provided. This is the power of open source.

Here I would like to tell you about the issue of code closure. The source code written in Python is usually not encrypted. If you want to publish your Python program, you are actually publishing the source code. This is different from C language. C language does not need to publish the source code. You only need to publish the compiled machine code (also It is the common xxx.exe file you see on Windows) and publish it. It is basically impossible to deduct C code from machine code. Therefore, any compiled language does not have this problem, while interpreted language must release the source code. What if you don’t want others to see or plagiarize the Python code you write? Use a packaging tool like py2exe to convert the Python source code into a form similar to an exe executable file. However, this is not absolutely safe. It just increases the threshold and difficulty of decompilation. For experienced people, it can be obtained your source code.

You may want to ask, what should I do if I want to make money by writing code and software and selling them? juvenile! In the current Internet era, there are fewer and fewer business models that rely on selling software licenses, and there are more and more models that rely on selling website services and mobile applications. This model does not require the source code to be given to others. Besides, the open source movement that is now in full swing is consistent with the spirit of freedom and openness on the Internet. There are countless excellent open source projects like the Linux ecosystem on the Internet. We must not overestimate the huge impact of the code we write. "commercial value". In the world of Python, open source is king. Don't worry about your code being copied and imitated, but try to improve your own level and ability. This is the foundation of your life.

3. Python application direction

1. General software development

Python supports functional programming and OOP object-oriented programming, and can undertake the development of any kind of software. Therefore, conventional software development, scripting, network programming, etc. are all standard capabilities.

2. Scientific computing

With the development of many program libraries such as NumPy, SciPy, Matplotlib, Enthought libraries, etc., Python is becoming more and more suitable for scientific calculations and drawing high-quality 2D and 3D images. Compared with Matlab, the most popular commercial software in the field of scientific computing, Python is a general programming language. It has a wider range of applications than the scripting language used by Matlab and is supported by more program libraries. Although many advanced functions and toolbox in Matlab are still irreplaceable, there are still many tasks in daily scientific research and development that can be done with Python.

3. Automated operation and maintenance

This is almost the exclusive domain of Python applications. As the preferred programming language for operation and maintenance engineers, Python has been deeply rooted in automated operation and maintenance. For example, Saltstack and Ansible are both well-known automation platforms.

4. Cloud computing

The open source cloud computing solution OpenStack is developed based on Python, and students who are engaged in cloud computing will understand it.

5. WEB development

There should not be too many web development frameworks based on Python, such as the familiar Django, Tornado, and Flask. The Python+Django architecture has a very wide range of applications, a very fast development speed, and a low learning threshold, which can help you quickly build usable WEB services.

6. Web crawlers

Also known as web spider, it is the core tool for obtaining data in the big data industry. Without web crawlers automatically, day and night, and highly intelligent crawling of free data on the Internet, there would probably be three-quarters fewer companies related to big data. There are many programming languages ​​that can be used to write web crawlers, but Python is definitely one of the mainstream, and its Scripy crawler framework is widely used.

7. Data analysis

On the basis of large amounts of data, combined with scientific computing, machine learning and other technologies, cleaning, deduplication, standardization and targeted analysis of data are the cornerstones of the big data industry. Python is one of the mainstream languages ​​for data analysis.

8. Artificial Intelligence

Python is a mainstream programming language in machine learning, neural networks, deep learning and other aspects of artificial intelligence, and has been widely supported and used.
Of course, in addition to the above mainstream and cutting-edge fields, Python also plays an important role in other traditional or special industries.

4. Python users

Having said so many advanced and cutting-edge Python technology directions, which companies are using Python?

The most famous ones in China are Zhihu and Douban, which are web services developed based on Python. Other companies such as Baidu, Alibaba, Taobao, Sohu, Kingsoft, Tencent, Shanda, NetEase, Tudou, Sina, Guoke and other companies are using Python to complete various tasks. Almost all Internet companies are recruiting Python programmers. .

Abroad, there are countless more. Google's Google App Engine, http://code.google.com, Google earth, Google crawler, advertising and other projects are all using Python extensively for development. And Facebook, Twitter and so on. Almost all Linux distributions have a built-in Python interpreter.

The following is an incomplete statistical chart:
Please add image description

5. Disadvantages of Python

We have just talked about the advantages of Python, but we also have to talk about its disadvantages. Any programming language has shortcomings, and Python is no exception.

The first disadvantage is that the running speed is relatively slow, much slower than C programs. This is a common problem of interpreted languages. When your Python code is executed, it will be translated line by line into machine code that the CPU can understand. This translation The process is very time consuming, so it will be slow. As a compiled language, C programs are directly compiled into machine code that the CPU can execute before running, so they are very fast. (But at the same time, you can understand that C language spends time doing the time-consuming work before production goes online, so the runtime is faster.)

But Python's slowness is not as serious as you think, because:

The speed of the program is no longer so important, and it does not have to be the pursuit of perfection:
in fact, we have already mentioned before that in the early days, CPUs were relatively expensive, computing resources were tight, and memory was also expensive. The speed at which the program runs and the time it takes are very important. . This is one of the reasons that leads computer science to study the efficiency of different algorithms. However, this is no longer the most important factor because chips are now cheaper and faster. Runtime is no longer your most expensive resource. A company's most expensive resource is now employee time. Or in other words, you. Getting things done within the specified time is more important than making the program faster. Python has a concise syntax and contains a large number of standard libraries and third-party libraries. With fewer statements, you can complete tasks that require hundreds of statements in other languages. This undoubtedly greatly improves the speed and efficiency of development and helps you complete the project in as short a time as possible. Complete the work within the time limit.

This is not to say that speed is not important at all, it just means that speed is no longer the only important thing and the only thing to consider. Nowadays, the speed of product development is far more important than the speed of program execution. At the end of the day, the only thing that will make your company live or die is time to market. The only way a company can survive is to innovate faster than your competitors. It won't matter how many good ideas you come up with if your competitors have already launched your product before you can.

There are bottlenecks in the overall system that run slower than Python programs:
if you are writing a network application, such as a web service, chances are that CPU time is not the bottleneck of your program. When your web server handles a request, it may make several network calls, such as to a database, or a cache server like Redis. While the services themselves may be fast, network calls to them are slow. If a single CPU cycle is equivalent to 1 second, then a network call from Beijing to Shanghai will be equivalent to 1 year. It can be seen how slow network calls are. What does this mean? It means that Python is not the slowest part of the system. There are running bottlenecks that are orders of magnitude slower than it and are stuck in the middle of the system, restricting the running speed of the entire system.

But no matter what, it is a fact that Python is slow. If you really need to speed up Python, you can write it in C and call it from Python.
In addition, programmer tycoon Donald Knuth said that premature optimization is the root of all evil. In the early and middle stages of development, pursuing running speed and efficiency is thankless. Agile development and rapid iteration are the kingly models of current software development, and Python was born for this.
The second problem is the GIL (Global Interpreter Lock) global interpreter lock, which is a mutex lock that prevents multiple threads from concurrently executing machine code. It is a product of a trade-off between functionality and performance. This is a historical legacy issue left when designing the Python language, and it was also limited by the limited strength of the technical team at that time. The specific technical details will not be explained first. The consequence is that when Python performs multi-threaded tasks, it is actually pseudo-multi-threaded and has poor performance. This has been criticized. Everyone can find it in any technical forum. Find a lively discussion on this issue. This problem of Python actually exists, and it will not be solved for a period of time. Why? This requires redesigning Python from the bottom up, which is extremely difficult, requires a lot of work, and will have a huge impact on the existing ecosystem. So what's the solution? Use the unofficial PyPy interpreter or coroutine mechanism.

The third issue that is not a disadvantage is the incompatibility between Python2 and Python3. This will be discussed later.

6. The Zen of Python

Finally, let us end our introduction to Python with Python's official motto, commonly known as the Zen of Python. In Python's IDLE or interactive interpreter, enter import this, and you will see the following paragraph:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea – let’s do more of those!

Translated it means:

Beautiful is better than ugly (Python aims to write beautiful code)
Clear is better than obscure (Beautiful code should be clear, well-named, and similar in style)
Simple is better than complex (Beautiful code should be simple, without complexity Internal implementation)
Complexity is better than clutter (if complexity is unavoidable, there should be no difficult-to-understand relationships between codes, and the interface should be kept simple)
Flat is better than nesting (beautiful code should be flat and not have too many nestings) )
Spacing is better than tightness (Beautiful code has proper spacing, don’t expect one line of code to solve the problem)
Readability is important (Beautiful code is readable)
These rules cannot be violated even in the name of the practicality of special cases ( These rules are paramount)
Don't tolerate all errors unless you know you need to (catch exceptions accurately, don't write except:pass style code)
When there are multiple possibilities, don't try to guess but try to find one, preferably The only obvious solution (if you're not sure, use the exhaustive method),
although it's not easy since you are not the father of Python (Dutch here refers to Guido), it
may be better to do it than not do it, but do it without thinking. It’s better not to do it (think carefully before doing it)
If you can’t describe your solution to others, it is definitely not a good solution; vice versa (solution evaluation criteria)
Namespaces are a wonderful idea that we should make more use of (advocate and call)

If you deeply understand and practice the above spirit, you can be sure that your coding level will be greatly improved!

Guess you like

Origin blog.csdn.net/Everly_/article/details/133136471