In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the PEP8 of python". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the PEP8 of python"?
First of all, let's introduce PEP8, which is a coding convention adapted from the python style guide article written by Guido (the father of python) (adding part of the style guide to Barry). Detailed PEP8 documentation can be found on the official website.
PEP8 official website documentation
Next, the editor picks out some specifications that need to be paid attention to:
Indent
Each level of indentation uses four spaces (you can indent four spaces at a time in code editing tab tabs).
Continue the line
The continuation line should be aligned with its package element.
You can use implicit line joins within parentheses, square brackets, and curly braces for vertical alignment, or you can use hanging line indentation alignment.
Note: when using hanging line indentation, you should take into account that the first line should not have parameters, and use indentation to distinguish that you are a continuation line.
Maximum length of row
The maximum number of characters for all lines is 79. Line continuation can be used if the maximum number of characters is exceeded.
For large chunks of text with no structural restrictions (such as document characters or comments), the maximum number of characters per line is limited to 72.
Blank line
The definition of the top-level function and class, separated by two blank lines.
The method definition in the class only needs to be separated by a blank line.
Import
Imports are usually done separately and at the top of the file.
Annotation
Block comments are made up of a # and a space plus comment content. Block comments are best indented to the same level as the code (although not indented and not discovered by the code editor).
Inline comments are two spaces before # on the block comment requirement.
Note: the code editor doesn't care about the quality of your comments, but that doesn't mean you can comment at will. Junk comments are better than no comments at all.
Naming convention
When naming, you should avoid indistinguishable letters as single-character variable names (such as lowercase L and uppercase I, which, of course, will not be discovered by the code editor).
Class names are generally capitalized, function names should be lowercase, and can be separated by underscores to improve readability.
Don't add semicolons.
Although a semicolon can be used as the end of a statement in the python2.x version, python actually identifies the end of a statement by a line break. So semicolons don't need to exist, and don't write multiple python statements in one line (because you can write multiple statements in one line, but this is against the PEP8 specification).
Space
Use spaces on both sides of punctuation in accordance with standard typesetting specifications, with no spaces in parentheses. Don't add spaces before commas, semicolons, and colons, but you should add spaces after them (except at the end of the line).
No spaces should be added before the left parenthesis of a parameter list, index or slice. Add a space on both sides of the binary operator, such as assignment (=), comparison (=,! =, =, in, not in, is, is not) and Boolean (and, or, not). The spaces on both sides of the arithmetic operator should be consistent. When (=) is used to indicate keyword parameters or default parameter values, do not use spaces on both sides of them.
At this point, I believe you have a deeper understanding of "what is the PEP8 of python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.