One
It is a good idea to specify the path to Python before writing:
#!/usr/bin/python
Python needs to be encoded in Linux: to avoid garbled Chinese
#-*-coding:utf-8–*-
Two in all kinds of languages, Python should be the most use of the language of indentation, his for statement even if there are many lines do not need to think java,c++, C like the use of {}, can be like JS, Swift with a newline character to represent a sentence, rather than use; Students who have studied the language background please note:
In Python's view:
If you change the way indentation is indented, such as indenting on the second for, it causes an error:
The following errors occur:
So here's the question: What's the effect of line break and indentation on Python???
The results of the operation are as follows:
1 line breaks can be thought of as Java, C + +, and no effect on the structure of the statement.
2 indents of the same distance can be treated as a pair of {}, regardless of whether the {} In any language should appear in pairs.
This Python statement that appears in the Demo1
It is equivalent to:
This is because {} does not match. That's why one of the following errors occurs
indentationerror:unexpected Indent
Or you can understand that a statement with the same indentation can be seen as a code block {}
Python language Tips