"Python enhancement proposal #8" Essentials study Excerpt

Source: Internet
Author: User

The Python Enhancement proposal #8 (8th Python enhancement proposal) is also known as PEP8, the style guide he has compiled for the Python code format.

Blank
    • Use space to represent indentation, not tab
    • Each layer of syntax-related indentation is represented by 4 empty Glyd
    • The number of characters per line should not exceed 79
    • There should be two blank lines between functions and classes in a file
    • In the same class, a blank line is applied between the methods
    • When using the following table to get list elements, call functions, or assign values to keyword parameters, do not add spaces on both sides
    • When assigning a value to a variable, the left and right sides of the assignment symbol should each be written with a space, and as long as one is good
Named
    • Functions, variables, and attributes should be spelled in lowercase letters, with an underscore between the words
    • Classes and exceptions should be named with the first letter of each word in the uppercase format
    • Class, the first parameter should be named self to represent the object's own
    • The first parameter of the class method, which should be named CLS, to represent the class itself
Expressions and statements
    • Instead of putting negative words in front of the entire expression, for example, you should write if a is not B instead of if not A is B
    • Do not judge whether the somelist is null by detecting the length of the method (such as if Len (somelist) = = 0), but rather by using the If not somelist notation, he assumes that null values are automatically evaluated as false
    • Instead of writing single-line if statements, for loops, while loops, and except compound statements, you should divide these statements into multiple lines to write in a clear
    • The import statement should always be placed at the beginning of the file
    • Which import statements in the file should be divided into three parts in order, representing standard library modules, third-party modules, and self-contained modules
Points
    • When writing Python code, you should always follow the PEP8 style guide
    • Using the same set of code styles as the vast majority of Python developers can make the project more collaborative for many people
    • Writing code in a style that has always been used to make subsequent modifications easier

The above is an excerpt from PEP8 and is interested to view http://www.python.org/dev/peps/pep-0008

"Python enhancement proposal #8" Essentials study Excerpt

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.