This article anti-theft chain: http://python789.blog.51cto.com
Python Basics-The first knowledge of Python
The author is an operations engineer, the following for the author to learn Python notes, hoping to bring you some help, write the wrong place, but also hope that we point out, or join us, we grow together.
1. Introduction to Python
The founder of Python is Guido van Rossum (Guido van Rossum). During the Christmas of 1989, Guido van Rossum to pass the time, determined to develop a new script interpreter, as an inheritance of the ABC language.
Python is an object-oriented, literal translation of computer programming language, Python advocating beautiful, clear, simple, is an excellent and widely used language
2. Python application field
-
cloud computing: applying OpenStack
-
automation: Saltstack, Ansible
-
system operations: essential language for operations personnel
-
graphics gui:pyqt, Wxpython,tkinte
-
web Development: Many large Web sites are developed for Python, Youtube, a typical web framework with Django
-
Scientific operations: artificial Intelligence, typical library numpy, SciPy, Matplotlib, Enthought librarys,pandas
-
Financial industry: in the field of financial engineering, as a dynamic language Python, the language structure is clear and simple, the library is rich, mature and stable, Scientific calculation and statistical analysis are very good, production efficiency is much higher than c,c++,java, especially good at strategy backtesting.
3. Python language analysis
Programming languages are categorized mainly from the following angles:
3.1. Python-Compiled
The translation program is responsible for translating our source code into the corresponding executable code. Professionally, it is called compilation (Compile), and the program responsible for compiling is naturally called the compiler (Compiler). If we write the program code is contained in a source file, then usually compiled after the direct generation of an executable file, we can run directly.
But for a more complex project, for ease of management, we usually distribute the code in various source files as different modules to organize. When compiling individual files, the target file (objectfile) is generated instead of the executable file that was previously said. Typically, a source file is compiled with a target file. The contents of these target files are basically executable code, but because they are only part of the entire project, we cannot run them directly. After all the source files have been compiled, we can finally "package" these semi-finished target files into an executable file, which is the responsibility of another program, because this process seems to be to assemble the target file containing executable code, so called link, The program that is responsible for linking is called the link program (Linker).
3.2, Python interpretation type
For example: If you plan to read a foreign language book and you don't know it, you can look for a translator, give him enough time to translate the whole book from beginning to end, and give you the native language version of the book to read. This process compiles, or you can immediately let the translator assist you in reading, let him give you a sentence to translate, if you want to look back to a chapter he also re-translated to you.
Two ways: The former is equivalent to the compiler: one at a time to convert all the code into machine language, and then write the executable file. And the latter is the equivalent of our interpretation: in the first moment of the program run, there is only the source program and no executable program, and each execution to a resource program execution, there will be a shell called the interpreter, the source code is converted to binary code for execution.
In the above view, Python is an interpreted language
4. Python Benefits
Python's positioning is "elegant", "clear", "simple", so the Python program always looks easy to understand. Development efficiency is very high, Python has a very powerful third-party library, basically you want to achieve any function through the computer, the Python official library has the corresponding modules to support, directly download the call, on the basis of the base library to develop, greatly reduce the development cycle.
1. Advanced language
When you write programs in the Python language, you don't have to consider the underlying details like how to manage the memory used by your program
2. Portability
Because of its open source nature, Python has been ported on many platforms (modified to make it work on different platforms)
3. Scalability
If you need a piece of your critical code to run faster or you want some algorithms to be private, you can write some of your programs in C or C + + and then use them in your Python program.
4, can embed the sex
You can embed python in your C/C + + program to provide scripting functionality to your program users.
5. Python drawbacks
1. Slow speed
Python runs much slower than the C language and is slower than Java.
2. Code cannot be encrypted
Because Python is an explanatory language, its source code is stored in the form of a name, but I do not think this is a disadvantage, if your project requires that the source codes must be encrypted, then you should not use Python in the beginning to implement.
3. Threads cannot take advantage of multiple CPUs
The Gil, the global interpreter lock, is the tool that the computer programming language interpreter uses to synchronize threads so that only one thread executes at any moment, and the Python thread is the native thread of the operating system. On Linux for Pthread, on Windows for win thread, the execution of threads is fully dispatched by the operating system. A Python interpreter process has a main thread and the execution thread for multiple user programs. Multi-threaded parallel execution is prohibited even on multicore CPU platforms due to the existence of the Gil.
6. How to implement Python
Python is a programming language, but there are a number of implementations that refer to the Python interpreter and the standard library that are compliant with the Python language specification.
The way Python is implemented is divided into three major categories
1.Cpython
2.Jpython
3.IronPython
6.1, CPython
CPython is the default Python interpreter, which is based on the fact that it is written in the portable ANSI C language code.
1. When executing python execution code, a Python interpreter is enabled, the source (. py) file is read into memory, then compiled into a bytecode (. pyc) file, and finally given to Python's virtual machine (PVM) to interpret and execute the contents line by row, then release the memory and exit the program.
2. When the second time in the execution of the current program, will be in the current directory to find the same name of the PYc file, if found, then run directly, otherwise repeat the above work.
The purpose of the 3.pyc file is to realize the reuse of code, why do you say so? Because Python thinks that as long as the import of imported files, it can be reused, then he will compile this file into a PYc file.
4.python will check the last modified date of the Py file and the PYc file before each load of the module, and if not, regenerate a copy of the PYc file, otherwise it will read the run directly.
6.2. Jython
Jython is a python implementation, Jython compiled Python code is Java bytecode, and then by the JVM (Java Virtual machine) execution, which means that at this time the Python program is not different from the Java program, but the source code is not the same. In addition, it is able to import and use any Java class like a Python module.
6.3, IronPython
IronPython is a C # implementation of Python, and it compiles Python code into C # intermediate code (similar to Jython) and then runs it with. NET language interoperability is also very good.
7. Python Installation
7.1. Windows
1. Download the installation package Python3.5 for Windows 2. Install the default installation path: C:\python3.5.2 3. Configure the environment variable (original value; C:\python27, remember that there is a semicolon in front of you) right-click Computer--Properties--Advanced system settings-environment variables-find a row with the variable named path double-clicking the-->python installation directory appends to the variable value. Use semicolons, split 4.Windows update python, unload load
7.2. Mac
1. Download the following software, directly double-click to install MAC OS X Download the installation package directly double-click the installation on line 2. Execute the Python3 command to query zhanghedemacbook-pro:~ zhanghe$ Pythonpython 2.7.10 ( Default, Jul, 18:31:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on Darwintype "help", "copyright", "Credits" or "license" for more information.>>>
8. Python easy to get started
Create a hello.py file to write the first program
[[email protected] ~]# cat hello.py#!/usr/bin/env pythonprint ("Hello world!") [email protected] ~]# python Hello.pyhello World
This article is from the "Python Path of Practice" blog, so be sure to keep this source http://python789.blog.51cto.com/13425423/1977737
Python Basics-The first knowledge of Python