[Python study notes] 04 program composition

This series is for yourself to learn Python notes. If there are errors, please correct me.

Composition of Python program

  1. Python programs are composed of modules. A module corresponds to the python source file, the general extension is .py
  2. The module is composed of statements. When running python, they are executed in the order of the statements in the module.
  3. Statements are the building blocks of Python programs, used to create objects, assign variables, call functions, and control statements

Python file creation and execution

In an interactive environment, only one statement can be executed at a time. In order to write multiple statements to achieve complex logic, we create a python file and execute the file. The specifics vary according to the python development tools you use, but they are basically the same.

Code organization and indentation

Many programming languages ​​divide code blocks by characters, and at the same time increase readability with the indentation of the code. Indentation is mandatory in Python.

When indenting, several spaces are allowed, but the number must be uniform. We usually use 4 spaces to indicate an indentation.

At the same time, avoid indentation styles that mix tabs or tabs with spaces. At present, the most commonly used is to set the tab character to 4 spaces,

Detailed description of PEB-8 code style recommended by Python: https://www.python.org/dev/peps/pep-0001/

Use notes

Annotate the text ignored by the Python interpreter in the program, used to record the description of the code

Use \line connector

There is no limit to the length of a line of program, but in order to be more readable, a relatively long line of program is usually divided into multiple lines. At this time, we can use the \ line connector to place it at the end of the line. The Python interpreter still interprets them as the same line

a = [1,2,3\
    4,5]

Guess you like

Origin blog.csdn.net/weixin_51656605/article/details/111713060