Preface
Interpreted of Python is an object-oriented computer programming language, by the Dutch Guidovan Rossum invented in 1989, the first Public version released in 1991, Python is a purely free software, source code and the interpreter retaining follow the GPL (GNU General Public License) protocol, Python syntax is concise and clear, feature a mandatory use whitespace (white space), as a language can indent, Python has a rich and powerful, it has often been nicknamed glue language, can be put in other languages make the various modules (especially c/c + +) easily join together,
Feature
(1) compiled languages: C, C + + to compile and run faster
(2) interpreted language: python platform compatibility
(3) dynamic languages: python runtime, detecting data types without declaration
(4) static languages: C, C + +, Java compile time, need to make the detection data type
Before using the statement
(5) strong data type, data type can only be cast type safe language
(6) weak data type of a variable gives the value of different data types
Conclusion: python is a dynamic explanatory strong data types of programming languages,
Basic knowledge of
1, variable naming rules
(1) identifier only by letters, Numbers or an underscore,
(2) the identifier of the first - a character can't be a digital,
(3) identifiers are case sensitive,
(4) the keyword can't declare as identifiers, such as' and ', 'as' and' assert ', 'break', 'class', 'continue' and 'def', 'del', 'elif', 'else', 'except', 'the exec', 'finally,' for ', 'from' and 'global' and 'if', 'import' and 'in', "is', 'lambda', 'not', 'or', along ', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'
Naming conventions: lowercase letters, between words separated with _, see a knowledge meaning
2, the statement
A Python program is composed of Python statements, usually -- line. Write a statement, such as: print (' Hello, '), print (' I am Python)
Python statements can not end, don't like C or C # behind the statement must have a semicolon (;) The end, a Python program, of course, can also according to the habits behind the statements use a semicolon (;) , also can write multiple statements on a line, at this point in the statement followed by a semicolon (; ) the end, such as: print (' "Hello,"); Print (I am Python ');
Statement: implement the modification operations, expression is used to calculate the county, the statement of county to perform
3, indentation, comments
The indentation
In front of the line of code to add a space, such doing can make the program more hierarchical structure, so as to make the program easier to read, in a Python program, the indentation is not arbitrary, level of indentation line statements (block) must be the same,
Annotation
Single-line comments:
well,Multiline comment: three quotes (three single quotes or double quotes 3)
Conditional statement and circular statement
1, the data type
Six standard data types:
Number (number) : int, float, Boolean
STR (string)
The list (list)
The tuple (a tuple)
Set (set)
Dict (dictionary)
Immutable data types: nmber (digital), STR (string), the tuple (a tuple)
Variable data types: list (list), dict (dictionary), the set (set)
2, operator
Python supports the following types of operator: arithmetic operators, comparison operators, assignment operators, logical operators, member operator, operator
1. The Python can at the same time for multiple variable assignment, such as a, b=1, 2
2. A variable can refer to different types of object by an assignment,
3. Contains two integer division operator:/returns a floating point number,//returns an integer,
4. In the mixed computing, Python will take the integer conversion become a floating point number,
3, the conditional statement
Python conditional statements is by one or more statement execution result (True or False), to perform a block of code
4, do statement
Python has the for and the while loop statements in the
Break statement: out of the loop body, if you are from the for or end in the while loop, any else block will not perform the corresponding cycle,
The continue statement: skip the loop body residual statement
Pass statement: maintain the integrity of the program structure Python statements pass is empty, is in order to maintain the integrity of the program structure, pass don't do anything, generally used as a placeholder statement
Cycle the else clause in not only call break, perform range () function can create a list of integers, generally in the for loop,
Function grammar: range (start, stop, [step])
Parameter description:
Start: counting from the start, the default is 0, such as range (5) is equivalent to the range (O, 5);
Stop: count to stop the end, but not stop. For example: the range (0, 5) is [0, 1, 2, 3, 4] no 5
Step, step length, the default is 1, for example: the range (0, 5) is equivalent to the range (0, 5, 1)