Tips for using the python language, and tips for using python
I
Before writing, you 'd better specify the python path:
#! /Usr/bin/python
Python needs to add encoding methods in linux: To avoid Chinese garbled characters
#-*-Coding: UTF-8 -*-
2. in various languages, Python should be the language that most uses indentation recognition. Even if there are multiple lines of its for statement, you do not need to think about java, C ++, c using the same {}, A line break can represent a sentence like JavaScript or swift, rather than a line break. If you have learned the language background, note the following:
In python's view:
If you change the indent method, for example, indent the second for, it will cause an error:
The following error occurs:
So the question is: what is the impact of line feed and indentation on python ???
The running results show that:
1. line feed can be considered as the; sign in java and c ++ without affecting the statement structure.
2 indentation with the same distance can be considered as a pair of {}, regardless of the language {} should appear in pairs.
The python statement that appears in demo1
It is equivalent:
It is because {} does not match. Therefore, the following error occurs:
IndentationError: unexpected indent
Or you can understand it as follows: statements with the same indentation can be viewed as code blocks {}
The above python usage tips are all the content shared by Alibaba Cloud. I hope you can give me a reference and support the help house.