Python introduction, python
Python Introduction
Before introducing python, let's talk about the differences between compiled and interpreted languages, object-oriented and process-oriented:
Advanced computer languages can be divided into program execution methods.Compiled languageAndInterpreted language.
Compile language: After the code is written, you need to use a special compiler for compilation to convert the code to a specific system platform (operating system) at one time) the machine language (machine code) that can be recognized and run ).
Advantage: the compiler usually has a pre-compilation process to optimize the code. Before running the code, compile the Code only once to generate a machine code file that can be directly run by the system without re-compilation. Therefore, the program execution efficiency in the compiled language is high, it can run independently from the language environment.
Disadvantage: If you need to modify it after compilation, the entire module needs to be re-compiled. during compilation, the machine code is generated based on the corresponding Runtime Environment (operating system). Porting between different operating systems will cause problems, different executable files need to be compiled according to the operating system environment.
For example, c, c ++, Go, Swift, Object-C, Pascal...
Interpreted language: After the code is written, you need to use the interpreter of this language to convert the code into an intermediate code (bytecode) that is easy to execute ), then, the bytecode is converted into a machine code that can be recognized by a specific system platform. It can be understood that every time an interpreted language program is executed, compilation is required, in a specific system.
Advantage: it has good platform compatibility and can run in any environment, provided that the interpreter of the corresponding platform is installed, with flexibility, and the source code is directly modified when the code is modified, then, you can perform the conversion to quickly deploy the service without downtime.
Disadvantage: every time you run the program, you must explain the conversion. You cannot generate programs that can be run directly on the system platform. The performance is inferior to that of compiled languages.
For example, JavaScript, Python, Ruby, PHP, Perl, Eriang...
For example, A and B are people in two countries and cannot communicate with each other because of their lack of language. If you want to communicate with each other and understand the other party's language, you need to translate. Compile-type language is the language in which A learns B. During communication, B can directly understand his ideas in B's language; what about interpreted language? A finds A translator who understands multiple languages and wants to express his meaning. He must first talk to the interpreter, then the interpreter translates the meaning of A to B. Because there is A translation process in the middle, the speed is slower than that of the compiled language, but the benefits are also true, this is the interpreter who understands A variety of languages. A wants to communicate with people from other countries and look for him directly. However, if you want to communicate with C, first, you must learn the C language. I understand this. If something is wrong, please leave a message to correct it.
Object-orientedAndProcess-oriented
Object-oriented: it is one thing: 'Who will do it? 'Who is the object. How can he do his own thing, anyway, the last group of objects can work together to do this well. For example, you can build your own computers.
Process-oriented: It's just one thing we should do. We don't care who will do it, but you just have to follow the steps we have prescribed. For example, you can create your own computer.
Python introduction:
The founder of python is Guido van rosum (Guido. van rosham), which was developed in 1989 and published in 1991;
Python is an advanced programming scripting language for interpreting, object-oriented, and dynamic data types. Its syntax is concise and clear, and it uses indentation to define statement blocks. It has the ability to customize and automatically recycle statements, the ability to automatically manage memory space usage. The python virtual machine itself applies to almost all systems. using tools such as py2exe, PyPy, and Pyinstaller, you can convert source code into programs executed without the python interpreter, here we mainly refer to CPython, which is a free programming software developed based on C language.
Python interpreter classification:
-
Cpython
Python official version, which is implemented in C language and most widely used. CPython converts the source file (py file) into a bytecode file (pyc file) and runs on a Python virtual machine.
-
Jyhton
Java Implementation of Python means that JAVA programs can be written in Python. Jython dynamically compiles Python code into Java bytecode and then runs it on JVM using JRE (java runtime environment.
-
IronPython
IronPython compiles Python code into C # bytecode and runs it on the CLR. (Similar to Jython)
-
PyPy (special)
Python uses the JIT Compiler (instant compiler) technology to compile Python bytecode into machine code.
-
RubyPython, Brython...
Python code execution process
Compile the source code into a bytecode (. pyc file), and then make friends with the Python Virtual Machine to execute the compiled bytecode and compile it into the machine code of a specific system platform.
Python usage:
-
Script:
Automatically execute common management tasks, such as adding users to the system, uploading files to websites, and downloading webpages without using browsers.
-
Website development:
As a tool for quickly creating dynamic websites, many Python projects such as Django, Bottle, and Zope are well received by developers.
-
Text processing:
Python provides powerful support for string and text file processing, including regular expressions and Unicode.
-
Scientific Computing:
The Python scientific computing Library provides functions for statistics, mathematical computation, and plotting.
Advantages and disadvantages of Python:
Easy to learn, easy to get started.
High-level languages do not need to consider the underlying details such as how to manage the memory used by your program.
Portability: All Your python programs can run on almost all the system platforms on the market without modification.
Scalability. If you need a piece of key code to run faster or want some algorithms not to be made public, you can write some of your programs in c or c ++, then use them in your python program.
Embedding. You can embed python into your c/c ++ program to provide script functions to your program users.
Slow speed; codes cannot be encrypted; threads cannot use multiple CPUs;
In actual work, it is developed on windows and runs on linux. So let's talk about the two installation methods of python:
Windows:
Download installation package: https://www.python.org/downloads/
We recommend that you download the 3.x version. The default installation directory is C: \ python35.
In 3.x, environment variables are automatically added during installation:
If you forget to select this option, you can add it as follows:
Configure environment variables:
Computer properties --> advanced system settings --> advanced --> environment variable --> find a line with the variable name path to open --> append the python installation directory to the variable value with a semicolon;
Linux:
CentOS 6.x comes with python on the default system CD, but its version is 2.x. we need to install version 3.x.
# wget # tar xf Python-3.5.3.tar.xz # cd Python-3.5.3 # ./configure --prefix=/usr/local/python35 # make all && make install # python -v # mv /usr/bin/python /usr/bin/python35 # vim /usr/bin/yum
Pycharm easy to use
PyCharm is a PythonIDE with a complete set of tools to help users improve their efficiency when developing using the Python language, such as debugging, syntax highlighting, Project management, code jump, smart prompts, Automatic completion, unit testing, and version control. In addition, the IDE provides some advanced functions to support professional Web development under the Django framework.
PyChram download
Official Website: http://www.jetbrains.com/pycharm
Windows: http://www.jetbrains.com/pycharm/download/#section=windows
Http://www.jetbrains.com/pycharm/download/#section=linux: Linux
MacOS: http://www.jetbrains.com/pycharm/download /#
Modify template
Note: The first line specifies the python path, and the second line specifies the script encoding format. You do not need to specify the py3 version, but py2 needs to be specified to be compatible.
Version Switch
If version 2.x or another version is installed, you can add
Character encoding modification to avoid garbled characters
Font settings
Adjust the display size with a pulley