2.1, Python, basic syntax, line breaks and indentation

2.1.3 Statement Wrap In
Python, a statement generally occupies a line, but sometimes a statement is too long and needs to be wrapped. The specific example is as follows: the
Insert picture description here
running result is shown in the figure.
Insert picture description here
In the example, the string in the first line of print() is too long. Write in two lines separately. Add a line continuation character "\" at the end of the first line to achieve this. However, when branching in [], {}, you don’t need to use backslash Bars, as in lines 3 and 4 in the example.
2.1.4 Indentation The
Python language is concisely reflected in the use of indentation to represent code blocks, unlike the use of {} in C++ or Java. The specific example is as follows: In the
Insert picture description here
example, the condition after the if is true, and the second and third lines are executed. , They use the same indentation to indicate a block of code. It should be noted here that the number of indented spaces is variable, but the statements in the same code block must contain the same indented spaces. The specific example is as follows: In the
Insert picture description here
example, the indentation of the 5th line and the 6th line is inconsistent. Throws an error.
The result of the operation is shown in the figure.
Insert picture description here
In Pycharm, indentation is automatically added. Use indentation in other text editors. It is recommended that you use 4 spaces as indentation. Try not to use tabs as indentation, because different text editors may have different blank widths represented by tabs.

Guess you like

Origin blog.csdn.net/weixin_43398418/article/details/110165394