Home >Backend Development >Python Tutorial >Python Learning [Part 1] Introduction to Python
Introduction to Python
Development History
Python 2 or 3?
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
Regarding speed: high-level languages cannot compare with C in terms of running speed
For speed: Python may be slightly inferior in speed
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.
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.
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 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 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 is a Python interpreter running on the Java platform. It can directly compile Python code into Java bytecode for execution.
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.
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.
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
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).
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中文网!