1. Indent: Indentation is the only way Python represents a block of statements;
All statements in a block of statements must use the same indentation, representing a contiguous sequence of logical lines;
The first line of the source file does not need to be indented (it is not allowed to start with any spaces);
The standard Python style is to use 4 spaces per indentation level;
How to represent a logical line across rows:
(1) ' \ ' can connect two adjacent physical lines into a logical line;
(2) [], {}, () can cross the physical line;
(3) Triple quotation string constants (including single and double quotes) can also span multiple lines, but one thing must be noted: when wrapping, you need to add the ' \ ' slash at the end of the physical line, otherwise the newline character will be included;
2.if statement:
The basic form is:
If judging condition:
Execute statement ...
Else
Execute statement ...
3.while Loop statement:
The basic form is:
While judging condition:
Execute statement ...
4.for Loop statement:
The basic form is:
For Iterating_var in sequence:
Statements
5.break statement:
Used to terminate the loop statement, that is, the loop condition does not have a false condition or the sequence has not been fully recursive, will also stop the execution of the loop statement;
6.continue statement:
Used to tell Python to skip the remaining statements of the current loop, and then proceed to the next round of loops;
The difference between range and xrange:
The xrange usage is exactly the same as range, and the difference is not a list object, but a generator.
When generating a large sequence of numbers, using xrange will be much better than range performance, because there is no need to open up a large amount of memory space.
Python indentation and Process Control statements