Python small note 1 (continually updated)

  In fact, start learning Python, it is already something six months ago, but has only intermittent read some very basic things to get started, there is no a very profound understanding.

  At present, I began to learn from the video, using windows platform, in fact, been relatively wanted to try linux system to learn, but most do not, then find a basic teaching video stool college, but using ubuntu, a graphical interface , since it is patterned into why not find a more convenient windows to learn.

  Text description taken from the part of the network, as part of personal understanding.

 

A. Python Introduction

  Since learning a new technology, we must begin to do something a brief description of its development, the origin, the advantages and disadvantages, application scenarios, and so on.

1. Python origin and development

  Python is founder Dutchman Guido van Rossum ( Guido Van Rossum) (I referred to as GD). During Christmas 1989, in Amsterdam, Guido Christmas in order to pass the boring, determined to develop a new script interpreter, as a succession of ABC language. Was chosen Python (boa constrictor meaning) as the name of the programming language, taken from the UK premiere of the 1970s TV comedy "Monty. Parsons's Flying Circus" (Monty Python's Flying Circus) .

  ABC language is a language of instruction in the design of GD. ABC language is beautiful, powerful, designed primarily for non-professional programmers, but ultimately did not achieve great success, GD I think it is because of its non-open, closed caused. So when the idea of ​​generating Python development, it is necessary to continue ABC beautiful language and powerful features, but also to avoid non-open its shortcomings, but rather to complete some of the content has not been implemented in this foundation.

  1991 a Python interpreter was born, it is to use the C language, and can call C library file.

 

2. Python advantages and disadvantages

2.1 Advantages

Less code: the same problem solving in general, Python code amount compared to java least 80%, which is very important in practice, less the amount of code to solve more problems;

Easy to learn: Python syntax beautiful, and deal with some problems less the amount of code, it should be simple and easier to learn is relative compared to java;

High-level language: When you write programs in Python, you do not need low-level details such as managing the memory of a class of your program uses

Portability: Because of its open-source nature, Python has been ported on many platforms (changed to make it work on different platforms). If you are careful to avoid the use depend on the characteristics of the system, then all your Python programs without modification to run on almost all platforms on the market

Scalability: If you need a critical piece of code to run very fast or want some algorithms are not open, you can put part of your program in C or C ++, and then use them in your Python programs.

Embeddable: You can embed Python within your C / C ++ program, which provides scripting capability to your program's users.

2.2 Disadvantages

Slow: Python is an interpreted language, according to the characteristics of interpreted languages, is a progressive code is compiled line by line, so compared to the C # language compiler, compile-time characteristics of a good run, it will slow a bit, but this slow eye observation people are less able to detect out.

Code can not be encrypted: Since Python is an interpreted language, so the code is clear text, as a security angle could cause some problems;

CPU utilization problem: Python threads can not take advantage of multi-CPU, GIL namely the global interpreter lock (Global Interpreter Lock), is a tool for computer programming language interpreter for thread synchronization so that any time only one thread in execution, Python threads is the operating system native threads.

 

3. Python applications

3.1 Cloud computing : cloud computing the hottest language, typical applications OpenStack

. 3.2 WEB development : many excellent WEB framework, many large sites are Python development, Youtube, Dropbox, watercress. . . Typical WEB framework Django

3.3 scientific computing, artificial intelligence. : Typical library NumPy, SciPy, Matplotlib, Enthought librarys , pandas

3.4 System operation and maintenance. : Operation and maintenance personnel must-language

3.5 Financial. : Quantitative trading, financial analysis, financial engineering, Python not only in use, and the most used, but also the importance of increased every year. The reason: As Python dynamic language, clear and simple language structure, rich library, mature and stable, scientific computing and statistical analysis is very fast hardware, production efficiency is much higher than c, c ++, java, especially good strategy backtesting

Graphics 3.6 the GUI. : PyQT, WxPython, TkInter

 

Two. Python is installed and ready environment

1. Run the environment and related procedures

1.1 Currently I am using win10 environment;

1.2. Python installation package ( https://www.python.org/ )

1.3. Pycharm installation package ( https://www.jetbrains.com/pycharm/download/ )

2. installation

Not elaborated here, because it is installed on the windows, it is very simple.

 

III. Based learning

1. print

And all of the language learning the first lesson began, most will use the "hello world", print can be seen from the literal meaning, content is output to the screen.

Format: print ( "content needs to output"), the basic common sense, in most programming languages, symbols are certain English half-width mode.

Print ( "the Hello world") 
Print ( "Hello, world")
Print (1.01 * 365)

It is seen from the figure: when the output of text, need to add "" double quotes wrapped outputting content, which are common in most languages, such as the sql varchar type data with respect to "wrap single quotes.

However, when the calculation output of particular types of content, can not be used quotes wrapped, because once the content is converted quoted wrapped, the program sets the contents of a text type, only the output display effect.

 

2. Comment

The role of the comment, as long as the people in the IT industry practitioners should have a basic knowledge of its importance, there is still long-winded it. In daily production scenarios, enterprise application projects, which are mostly developers to write to form working groups to develop, so the presence of this code is the transfer of technology for everyone in the team, and so are not the same level of understanding, which when the code is more complex logic functions at the comments written on the original developer, played the role of a note is particularly important, even if the code is not used for the transfer, the code set down over many years, How great amount of code, if in the early problems we need to review the underlying code, not be able to remember to write this code, in the end what is the meaning, why write. So a competent IT professionals, must have the habit to write notes.

Principles comment: write only a comment on the important part; comments as concise as possible.

# Learning a single line comment 
print ( "single-line comments") Code tail Note #
# Note second single-line
print (3 ** 3)

From the above chart: # comment identifier is, when writing comments, to write a "#" then a space lattice (this is for aesthetic, pycharm have quick formatting codes function), then write your comment on the content. Comments can write a single line, you can also write at the end of the code.

 

3. arithmetic operators

"+", "-", "*", "/": addition, subtraction;

"//": Take divisible, such as 7/2 = 1 then 3 ... 7 // 2 = 3;

"%": Go to the remainder, e.g. 2 ... 8% 3 = 2 3 = 2 then 8%;

"**": a power of, for example, 3 * 4, then on behalf of Mathematics 3⁴ = 81;

Seen from the figure: the code in line 8, not only text, but also arithmetic operator "*", then processing logic in Python is repeated text.

 

4. Variable

4.1 Variable type and assignment

Here only briefly mention a few common types of variables.

string: string type, the most common and also the first study to master the content, use the "" double quotes wrapped content;

int: integer, and the majority of IT technology languages, int integer natural number, digital content can be directly fill out;

bool: Boolean type, commonly used to make a judgment, True / False;

float: float with a decimal point, directly fill out the numerical content;

# Different types of variables 
# String Type
name = "Bob"
# int Type
Age = 18 is
# BOOL type
Gender = False
# a float type
Hight = 1.75
# a float type
weight = 75.0
# outputs all information
# print ( "Name:" + name "Age:" + age, "whether the boys:" + gender, "height:" + hight, "weight" + weight)
Print ( "name:", name)
Print ( "age:", Age)
Print ( " whether the boy: ", Gender)
Print (" height: ", Hight)
Print (" weight: ", weight)
Print (name + str (Age))

It is seen from the figure:

  • Assignment of each variable manner, using the "=" equal to the number assigned to the variable value to the right of the left side, and the majority of the Python programming language "=" is an assignment means, the effect may be the same mathematics "=" , but the concept should not be confused;
  • Output variables, variables can directly fill in the print medium;
  • Python value based on the input, the automatic determination of the type of variable;

 

4.2 calculate variables

Definition of price price, weight, weight, the amount of money

# Define price 
. Price = 7.99
#define weight
weight = 6.5
# Amount Calculation
Money = weight. Price *
# 5 return dollars
Money = Money - 5
# Amount output
print (money)

It is seen from the figure:

  • Python will be based on the values ​​entered automatically determine the variable type, which is an expression of convenience, but in most such as java, c # language, etc., must first define the variable type, then the assignment, so at this point it is Python saving the amount of codes of variable type definitions;
  • Variables can be calculated directly using the variable band calculation arithmetic operators, may be calculated from the variable and the variable, provided that the type of the variable to be consistent;

 

4.3 Variable types of conversions

# Different types of variables 
# String Type
name = "Bob"
# int Type
Age = 18 is
# BOOL type
Gender = True
# a float type
Hight = 1.75
# a float type
weight = 75.0
# outputs all information
# print ( "Name:" + name "Age:" + age, "whether the boys:" + gender, "height:" + hight, "weight" + weight)
Print ( "name:", name)
Print ( "age:", str (age)) # convert str type output
print ( "whether the boy:", str (gender)) # convert str type output
print ( "height:", Hight)
print ( "weight:", weight)
Print (name + str (Age ))

It is seen from the figure and the code:

  • Use str (), can be converted to the character type variable;
  • In this style, the same int () float type variables can also be converted to integer variables;

 

Guess you like

Origin www.cnblogs.com/airlinp/p/12461506.html
Recommended