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