Python Learning [Part 1] Introduction to Python
Introduction to Python
Development History
Python 2 or 3?
1. Introduction to Python
The founder of python is Guido van Rossum. During the Christmas period of 1989, in order to kill time in Amsterdam, Guido van Rossum decided to develop a new script interpreter as a successor to the ABC language.
#In the latest TIOBE rankings, Python has overtaken PHP to occupy the fifth place. Python advocates elegance, clarity, and simplicity, and is an excellent and widely used language.
Python can be used in many fields, such as: data analysis, component integration, network services, image processing, numerical computing and scientific computing and many other fields. At present, almost all large and medium-sized Internet companies in the industry are using Python, such as: Youtube, Dropbox, BT, Quora (China Zhihu), Douban, Zhihu, Google, Yahoo!, Facebook, NASA, Baidu, Tencent, Autohome, Meituan et al. Things that Internet companies widely use Python to do generally include: automated operation and maintenance, automated testing, big data analysis, crawlers, Web, etc.
Currently Python’s main application areas:
Cloud computing: the most popular language for cloud computing, typical application OpenStack
- ##WEB Development: Many excellent WEB frameworks, many large websites are developed in Python, including Youtube, Dropbox, and Douban. . . , Typical WEB frameworks include Django
- Scientific operations, artificial intelligence: Typical libraries NumPy, SciPy, Matplotlib, Enthought libraries, pandas
- System operation Wei: One of the essential languages for operation and maintenance personnel
- Finance: quantitative trading, financial analysis, in the field of financial engineering, Python is not only used, but also used the most, and its importance is increasing year by year. . Reason: As a dynamic language, Python has a clear and simple language structure, rich libraries, mature and stable, efficient scientific calculation and statistical analysis, and its production efficiency is much higher than that of c, c++, and java. It is especially good at strategy backtesting
- Graphic GUI: PyQT, WxPython,TkInter
Regarding speed: high-level languages cannot compare with C in terms of running speed
For speed: Python may be slightly inferior in speed
- Python's positioning is "elegant", "clear", and "simple", so Python programs always look simple and easy to understand. Beginners learning Python are not only easy to get started, but also can write very, very complex programs if they go deeper in the future.
- The development efficiency is very high. Python has a very powerful third-party library. Basically, if you want to realize any function through the computer, the official Python library has corresponding modules to support it. Download it directly. After the call, development is carried out on the basis of the basic library, which greatly reduces the development cycle and avoids reinventing the wheel.
- High-level language————When you write a program in Python, you don’t need to think about low-level details such as how to manage the memory used by your program
- Portability - Due to its open source nature, Python has been ported to many platforms (with modifications to enable it to work on different platforms). If you carefully avoid using system-dependent features, then all of your Python programs can run without modification on almost any system platform on the market
- Scalability———— — If you need a critical piece of your code to run faster or want certain algorithms to be kept private, you can write parts of your program in C or C++ and use them in your Python program.
- Embeddability - You can embed Python into your C/C++ program to provide scripting functionality to your program users.
Slow speed. Python runs much slower than C language and slower than JAVA. Because Python is an interpreted language, your code will be translated line by line during execution. into machine code that the CPU can understand. This translation process is very time-consuming, so it is very slow. The C program is directly compiled into machine code that the CPU can execute before running, so it is very fast. But in fact, the slow running speed referred to here cannot be directly perceived by users in most cases, and must be reflected with the help of testing tools.
The code cannot be encrypted because PYTHON is an interpreted language and its source code is stored in text form. However, I don’t think this is a disadvantage. If your project requires source code The code must be encrypted, then you shouldn't use Python to implement it in the first place.
Threads cannot take advantage of the problem of multiple CPUs. This is the most criticized shortcoming of Python. GIL is the Global Interpreter Lock (Global Interpreter Lock), which is used by computer programming language interpreters. A tool for synchronizing threads so that only one thread is executing at any time. Python threads are native threads of the operating system. It is pthread on Linux and Win thread on Windows. The execution of the thread is completely scheduled by the operating system. A python interpreter process has a main thread and multiple user program execution threads. Even on multi-core CPU platforms, parallel execution of multi-threads is prohibited due to the existence of GIL. Regarding the compromise solution to this problem, we will discuss it in detail in the thread and process chapters later.
Types of Python
When we write Python code, what we get is a Python code containing A text file with a .py extension. To run the code, you need the Python interpreter to execute the .py file.
Since the entire Python language is open source from specification to interpreter, in theory, as long as the level is high enough, anyone can write a Python interpreter to execute Python code (of course it is very difficult). In fact, multiple Python interpreters do exist.
CPython
After we downloaded and installed Python 2.7 from the official Python website, we directly got an official version of the interpreter: CPython. This interpreter is developed in C language, so it is called CPython. Running python from the command line starts the CPython interpreter.
CPython is the most widely used Python interpreter. All code in the tutorial is also executed under CPython.
IPython
IPython is an interactive interpreter based on CPython. That is to say, IPython is only enhanced in the interactive mode, but the function of executing Python code is completely the same as CPython. the same. For example, although many domestic browsers have different appearances, their cores actually call IE.
CPython uses >>> as the prompt, while IPython uses In [serial number]: as the prompt.
PyPy
PyPy is another Python interpreter that targets execution speed. PyPy uses JIT technology to dynamically compile Python code, so it can significantly improve the execution speed of Python code.
Most Python codes can be run under PyPy, but there are some differences between PyPy and CPython, which results in the same Python code executing under the two interpreters may have different results. If your code is to be executed under PyPy, you need to understand the differences between PyPy and CPython.
Jython
Jython is a Python interpreter running on the Java platform. It can directly compile Python code into Java bytecode for execution.
IronPython
IronPython is similar to Jython, except that IronPython is a Python interpreter running on the Microsoft .Net platform and can directly compile Python code into .Net bytecode.
Summary
There are many Python interpreters, but the most widely used one is CPython. If you want to interact with Java or .Net platform, the best way is not to use Jython or IronPython, but to interact through network calls to ensure the independence between programs.
2. History of Python development
- ## In 1989, in order to pass the Christmas holiday, Guido began to write Python language translater. 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 ideal: to create a language between C and shell that is comprehensive, easy to learn, easy to use, and scalable.
- 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.
- Granddaddy of Python web frameworks, Zope 1 was released in 1999 ##Python 1.0 - January 1994 added lambda, map, filter and reduce .
- ##Python 2.0 - October 16, 2000, added a memory recycling mechanism, forming the basis of the current Python language framework
- Python 2.4 - November 30, 2004, the same year that the most popular WEB framework Django was born
- Python 2.5 - September 19, 2006
- Python 2.6 - October 1 , 2008
Python 2.7 - July 3, 2010
In November 2014, it was announced that Python 2.7 would be supported until 2020, and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible
Python 3.0 - December 3, 2008
Python 3.1 - June 27, 2009
Python 3.2 - February 20, 2011
Python 3.3 - September 29, 2012
Python 3.4 - March 16, 2014
Python 3.5 - September 13, 2015
三、Python 2 or 3?
In summary : Python 2.x is legacy, Python 3.x is the present and future of the language
Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of
extended support for this end-of-life release. The 2.x branch will see no new major releases after that. 3.x is
under active development and has already seen over five years of stable releases, including version 3.3 in 2012,
3.4 in 2014, and 3.5 in 2015. This means that all recent standard library improvements, for example, are only
available by default in Python 3.x.
Guido van Rossum (the original creator of the Python language) decided to clean up Python 2.x properly, with less regard for backwards compatibility than is the case for new releases in the 2.x range. The most drastic improvement is the better Unicode support (with all text strings being Unicode by default) as well as saner bytes/Unicode separation.
Besides, several aspects of the core language (such as print and exec being statements, integers using floor pision) have been adjusted to be easier for newcomers to learn and to be more consistent with the rest of the language, and old cruft has been removed (for example, all classes are now new-style, "range()" returns a memory efficient iterable, not a list as in 2.x).
py2与3的详细区别
PRINT IS A FUNCTION
The statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old statement (PEP 3105). Examples:
Old: print "The answer is", 2*2 New: print("The answer is", 2*2) Old: print x, # Trailing comma suppresses newline New: print(x, end=" ") # Appends a space instead of a newline Old: print # Prints a newline New: print() # You must call the function! Old: print >>sys.stderr, "fatal error" New: print("fatal error", file=sys.stderr) Old: print (x, y) # prints repr((x, y)) New: print((x, y)) # Not the same as print(x, y)!
You can also customize the separator between items, e.g.:
print("There are <", 2**32, "> possibilities!", sep=""
ALL IS UNICODE NOW
从此不再为讨厌的字符编码而烦恼
还可以这样: (A,*REST,B)=RANGE(5)
<strong>>>> a,*rest,b = range(5) >>> a,rest,b (0, [1, 2, 3], 4) </strong>
某些库改名了
Old Name |
New Name |
_winreg |
winreg |
ConfigParser |
configparser |
copy_reg |
copyreg |
Queue |
queue |
SocketServer |
socketserver |
markupbase |
_markupbase |
repr |
reprlib |
test.test_support |
test.support |
还有谁不支持PYTHON3?
One popular module that don't yet support Python 3 is Twisted (for networking and other applications). Most
actively maintained libraries have people working on 3.x support. For some libraries, it's more of a priority than
others: Twisted, for example, is mostly focused on production servers, where supporting older versions of
Python is important, let alone supporting a new version that includes major changes to the language. (Twisted is
a prime example of a major package where porting to 3.x is far from trivial
更多Python学习【第一篇】Python简介 相关文章请关注PHP中文网!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This article will explain how to improve website performance by analyzing Apache logs under the Debian system. 1. Log Analysis Basics Apache log records the detailed information of all HTTP requests, including IP address, timestamp, request URL, HTTP method and response code. In Debian systems, these logs are usually located in the /var/log/apache2/access.log and /var/log/apache2/error.log directories. Understanding the log structure is the first step in effective analysis. 2. Log analysis tool You can use a variety of tools to analyze Apache logs: Command line tools: grep, awk, sed and other command line tools.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The readdir function in the Debian system is a system call used to read directory contents and is often used in C programming. This article will explain how to integrate readdir with other tools to enhance its functionality. Method 1: Combining C language program and pipeline First, write a C program to call the readdir function and output the result: #include#include#include#includeintmain(intargc,char*argv[]){DIR*dir;structdirent*entry;if(argc!=2){

This article discusses the DDoS attack detection method. Although no direct application case of "DebianSniffer" was found, the following methods can be used for DDoS attack detection: Effective DDoS attack detection technology: Detection based on traffic analysis: identifying DDoS attacks by monitoring abnormal patterns of network traffic, such as sudden traffic growth, surge in connections on specific ports, etc. This can be achieved using a variety of tools, including but not limited to professional network monitoring systems and custom scripts. For example, Python scripts combined with pyshark and colorama libraries can monitor network traffic in real time and issue alerts. Detection based on statistical analysis: By analyzing statistical characteristics of network traffic, such as data

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

This article will guide you on how to update your NginxSSL certificate on your Debian system. Step 1: Install Certbot First, make sure your system has certbot and python3-certbot-nginx packages installed. If not installed, please execute the following command: sudoapt-getupdatesudoapt-getinstallcertbotpython3-certbot-nginx Step 2: Obtain and configure the certificate Use the certbot command to obtain the Let'sEncrypt certificate and configure Nginx: sudocertbot--nginx Follow the prompts to select

Configuring an HTTPS server on a Debian system involves several steps, including installing the necessary software, generating an SSL certificate, and configuring a web server (such as Apache or Nginx) to use an SSL certificate. Here is a basic guide, assuming you are using an ApacheWeb server. 1. Install the necessary software First, make sure your system is up to date and install Apache and OpenSSL: sudoaptupdatesudoaptupgradesudoaptinsta
