Python Coding specification

Source: Internet
Author: User

Python Coding Specification

Reference

https://www.python.org/dev/peps/pep-0008/

http://zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/contents/

Https://google.github.io/styleguide/pyguide.html

Coding style conventions when developing with Python (EPES:PEP 008 Style Guide for Python code)

    • Semicolon: Do not add a semicolon at the end of a line, and do not use a semicolon to place two commands on the same row.
    • Line length: No more than 80 characters per line
    • Indent: Use 4 spaces to indent the code, not tab, or use the tab space to mix
    • Blank line: null 2 rows between function or class definition, 1 rows between method definitions
    • Spaces: Do not precede commas, semicolons, and colons with spaces, but should be appended to them (except at the end of the line).
    • Class: If a class does not inherit from another class, it is explicitly inherited from object. The same is true for nested classes.
    • Import format: Each import should have an exclusive line
    • Statement: Typically each statement should have a single row

named

module_name
package_name
method_name
instance_var_name
function_parameter_name
local_var_name
Function_name
classname
exceptionname
Span style= "font-family:"microsoft yahei"; font-size:16px ">global_var_name

1, the so-called "internal (Internal)" means that only the module is available, or, within the class is protected or private

    • Use a single underscore (_) to indicate that a module variable or function is protected (not included when using from the package import *)
    • An instance variable or method that starts with a double underscore (__) represents a private in-class

2, the related classes and top-level functions in the same module. Unlike Java, there is no need to restrict a class to a module

3. A word (hump named) that starts with a capital letter for the class name, but the module name should be underlined in lowercase (such as lower_with_under.py). Although there are already many existing modules that use a name similar to capwords.py, it is now discouraged because if the module name happens to coincide with the class name, it can be confusing.

Python Coding specification

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.