Python overview and development environment installation

**

Python overview and development environment installation

**

1. Introduction to Python language*

Python language is one of the few programming languages that can be called simple and powerful .
Python is easy to learn , and it pays more attention to how to solve problems, rather than entangled in the syntax and structure of the programming language.
Python is an interpreted , object - oriented , high-level programming language.
Python is an open source, free , interactive , and cross-platform portable scripting language.

**

Second, the advantages of Python

**
The design of Python mixes the characteristics of software engineering in traditional languages ​​and the ease of use of scripting languages. It has the following characteristics:
open source, easy to maintain, portable, easy to use, simple and elegant, extensive standard library, powerful, and extensible , Embeddable, explanatory...
1. Python is very fast to start, and you can learn Python programming directly through the command line interactive environment.
2. Python has relatively few keywords, simple structure, and easier learning.
3. Python's grammar is very elegant, even without the braces, semicolons and other special symbols like other languages, which represents a minimalist design idea.
Reading Python programs is like reading English, although the English requirements are very strict!
4. Python has its own rich and powerful library, which can help you handle various tasks, including database, web browser, FTP, email, password system, GUI (graphical user interface) and other operations.
And due to the open source nature of Python, there are also many third-party high-quality extension libraries, such as web development (flask), crawler (Scrapy), scientific computing (Scipy), and so on.
5. Python's scalability is reflected in its modules. Python has the richest and most powerful class library in scripting languages, covering most application scenarios such as file I/O, GUI, network programming, database access, and text operations.
6. Programs written in Python language do not need to be compiled into binary code. You can run the program directly from the source code.
Inside the computer, the Python interpreter converts the source code into an intermediate form of bytecode, and then translates it into the machine language used by the computer to run.

**

Three, the shortcomings of Python

**
1. The running speed is slow.
2. Python is an interpreted language, and translation into machine code at runtime is very time-consuming.
3. The code cannot be encrypted.
3. An interpreted language release program is to release the source code

Python typical application

Data analysis, scientific computing, conventional software development, artificial intelligence, web crawler, WEB development

**

Four, coding standards

**

1. Indentation
Python is a hard requirement for code indentation, and indentation is strictly used to reflect the logical subordination of the code.
Generally, 4 spaces are used as an indentation unit, and code blocks of the same level should have the same indentation.
In the structure of function definition, class definition, selection structure, loop structure, exception handling structure and with statement, the corresponding function body or statement block must have corresponding indentation.
When a line of code is not at the same indentation level as the previous line of code, and the indentation level of a previous line of code is
the same, it means that the previous code block ends.

2. Space and blank line
Add a blank line after each class, function definition or a complete function code.
Add a space on each side of the operator, and add a space after the comma to make the code a little looser, not too dense, and improve readability.
When actually writing code, this specification needs to be used flexibly. Adding blank lines and spaces in some places will improve readability and make the code easier to read.
But if you bluntly add spaces on both sides of all operators and after the comma, it will be counterproductive.

One space on each side of the binary operator [=,-,+=,==,>,in,is not,and], such as:
a = b + c
without a space after the unary prefix operator, such as:
if !flg: pass
brackets (including parentheses, square brackets and curly brackets) without spaces before and after. Such as:
do_something(arg1,arg2)
do not add spaces before commas, semicolons, and colons, but should add them after them (except at the end of the line)

3. Identifier names
must start with English letters, Chinese characters or underscores. Although Python 3.x supports the use of Chinese as identifiers, it is generally not recommended.
The name can contain Chinese characters, English letters, numbers and underline, without spaces or any punctuation.
Keywords cannot be used, such as yield, lambda, def, else, for, break, if, while, try, return, etc.
Sensitive to the case of English letters, for example, student and student are different variables.
It is not recommended to use system built-in module names, type names or function names, and imported module names and their member names as variable names or custom function names. For example, variable names such as type, max, min, len, and list are not recommended. For variable names, it is not recommended to use math, random, datetime, re, or other built-in module and standard library names as variable names or custom functions.

4. Line continuation
Try not to write too long sentences, and try to ensure that a line of code does not exceed the width of the screen.
If the statement is really too long and exceeds the screen width, it is best to use a line continuation character "" at the end of the line to indicate that the next line of code still belongs to this statement, or use parentheses to enclose multiple lines of code to indicate that it is a statement.
expression1 = 1 + 2 + 3\ #Use \ as a line continuation character
+ 4 + 5
expression2 = (1 + 2 + 3 #Put multi-line expressions in parentheses to indicate a statement
+ 4 + 5)

5. Comments Make necessary comments
on key codes and important business logic codes to facilitate code reading and peacekeeping.
There are two common comment forms in Python:
# and triple quotes. The pound sign # is used for single-line comments, indicating that the content after the # symbol in this line will not be run as code;
triple quotation marks are often used for comments of large descriptive texts, and can also be used to delimit long strings containing line breaks.

In key parts of the code (or more complicated places), you should write comments as much as possible if you can write comments.
More important comment paragraphs, separated by multiple equal signs, can be more eye-catching and highlight the importance.

6. Parentheses are
used to indicate that multiple lines of code are a statement.
It is also commonly used to modify the calculation order of expressions or increase code readability to avoid ambiguity.

**

Five, Python development environment installation

**
Python is cross-platform. Can run on Windows, Mac and various Unix/Linux systems.
Python code is a text file with a .py extension. To run the code, you need to install a Python interpreter.
IDLE is installed with Python by default.
Anaconda: An excellent platform for machine learning and data analysis in Python.

Spyder configuration and use

Spyder is an integrated development environment (IDE) using Python programming language for scientific computing. It combines the advanced editing, analysis, debugging functions, interactive execution and other functions of the comprehensive development tool, which brings great convenience to users

.
Spyder features:

1. MATLAB-like design:
Spyder refers to MATLAB in the design. The variable viewer imitates the function of "workspace" in MATLAB, and has a PYTHONPATH management dialog box similar to MATLAB, which is very friendly to Python beginners who are familiar with MATLAB.
2. Rich resources and easy to find.
Spyder has the functions of variable automatic completion, function call prompts, and access to documentation help anytime and anywhere. The resources and documentation links that can be accessed include Python, Matplotlib, NumPy, Qt, IPython and other tools and toolkits. Manual.
Beginner-friendly
3. Spyder provides interactive tutorials and shortcut cheat sheets for new users in its menu bar [help], which can help new users quickly and intuitively understand Spyder's user interface and how to use it.
4. Abundant tools and powerful functions
. In addition to the editor, debugger, user graphical interface and other components commonly found in general IDEs , Spyder also has components such as object viewer, variable viewer, interactive command window, and historical command window. It also has a variety of functions such as array editing and personalized customization.

Guess you like

Origin blog.csdn.net/qq_43480434/article/details/112588443