Analysis of Python -- 1 grammar notes

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Long time did not write the article, recently prepared to do a Python website, review. Since writing, according to the official website to write a specification, specification, ha ha.

What is the wrong place, welcome readers pointed out.

A, logic and physical line

The Python program is through grammar analyzer on the symbol (marker) flow analysis. It consists of a series of logic, logical line is composed of one or more physical lines.

And what is the logic? Logic is a realization of a function statement.

a = 1

The above example explanation: here at a = 1, the assignment to a is a logical line; in the screen print the number 3, is also a logical line.

Physical line is one part of a logical line, because the logical line may be composed of several physical line.


The above example: print is a physical line, and the 3 is a physical line, which constitute a logical line.

However, in the if statement, if 2 conditions, 1> 0 and 2> 0, to meet the output 3. So we should not directly apply the two conditions separated.

So, can write this:

if 1>0 \       #Or if 1>0 and \
and 2>0 :    #  2>0:
    print(3)   #    print(3)

In the above example: in and followed by explicit connection ("\"), this symbol assists two physical lines are connected together to form the logical line.

In addition, to annotate the code using the # in Python.

Two, on the indentation

In Python there are generally two kinds of indentation, the first kind is spaces, second by pressing the tab key.

Python grammar rules, the first line of the program can not have spaces.

While the tab bond includes 8 spaces (this is the same as in UNIX, is my idle boring when found, you do not believe you can count~_~).


Here more or less on numbers, text, symbols, text representation.

1,Escape character:

  Escape character inherited the C style in Python, the commonly used \n, \b, \t, and C usage is the same.


  Decimal system: "1"..."9"...“0”

  Octal number system: "0" ("o" | "O") "1"...“9”"0"

  Binary: "0" ("b" | "B") "1"...“9”"0"

  Hexadecimal: "0" ("x" | "X") "1"...“9”"0"

3,Floating point float:

  Then there are several forms, 3.14 10. .001 1e100 3.14e-10 0e0


  Python, and the complex of this type, such as: 3.14j , 10.j , 10j , .001j , 1e100j , 3.14e-10j


+       -       *       **      /       //      %
<<     >>      &       |       ^       ~
<      >       <=      >=      ==      !=

Four, summary

  On the python grammar, first here, the next article, I will describe the details of the python data type.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Adair at November 14, 2013 - 6:41 PM