Python overview 01 coding standards

Python overview

From today, we will continue to update some content about python learning, hoping to help readers.

01 coding standards

Overview

1. There are hard requirements for code indentation, indentation reflects logic
2.4 Space is an indentation unit, and code blocks of the same level have the same indentation
3. Function definition, class definition, selection structure, loop structure, exception handling structure In structures such as with statements, the corresponding function body or statement block must have corresponding indentation
4. When a line of code is not at the same indentation level as the previous line of code, and the indentation level is the same as that of the previous line of code, Indicates the end of the previous code block.

Spaces and blank lines (recommended)

1. Add a blank line after each class, function definition or a complete function code
2. Add a space on each side of the operator, and +space after the comma (optional)
3. Generally, each side of the binary operator One empty space
4. No spaces after the unary prefix operator
5. No spaces before and after the brackets
6. No,;: Add space before but it is best to add it after (except at the end of the line)

Identifier naming

Must start with English letters, Chinese characters, or underscores (Chinese is not recommended) The
name can contain Chinese characters, English, numbers, underscores, no spaces or any punctuation marks,
no keywords,
case sensitivity, it is
not recommended to use the internal module name and type of the system Name or function name and its member variable name or custom function name

Continuation

1. Try not to write too long sentences, and one line should not exceed the width of the screen
2. Use \ for continuation, or use parentheses to enclose multiple lines of code to indicate a sentence

Comment

# And triple quotation marks
Triple quotation marks are used for large comments

Parentheses

1. Used to express multiple lines of code as a statement
2. Also used to modify the calculation order of expressions or increase readability

Guess you like

Origin blog.csdn.net/bj_zhb/article/details/104565737