PEP8 code style

  1. Each indented using four spaces.
  2. Continued row or maintain parentheses, brackets, by elements such as braces wrapped vertical alignment, or hidden in the Python line (Note: should be relative to the internal block def) inside, or using a hanging indent. Use hanging indent Notes: The first line can not have arguments to put further separated by other lines indented area. (E.g)
    # Aligned with opening delimiter.
    foo = long_function_name(var_one, var_two,
                             var_three, var_four)
    
    # More indentation included to distinguish this from the rest.
    def long_function_name(
            var_one, var_two, var_three,
            var_four):
        print(var_one)
    
    # Hanging indents should add a level.
    foo = long_function_name(
        var_one, var_two,
        var_three, var_four)
  3. The first non-white character just below the right parenthesis in a multi-line structure, right bracket, right brace should be placed in the last row, as follows:
    my_list = [
        1, 2, 3,
        4, 5, 6,
        ]
    result = some_function_that_takes_arguments(
        'a', 'b', 'c',
        'd', 'e', 'f',
        )
    
  4. Limit the maximum line length is 79 characters.
  5. Top-level functions and classes defined using two vertically separated by blank lines. The method defined in class using a blank line separator.

  6. Code in the core Python release version should always use UTF-8coding (or in use in Python 2 ASCII).
  7. importDifferent modules should be independent line
  8. Use spaces
      • Maintaining a compact and behind the comma, semicolon, or colon
      • As in the colon sections as binary operator, it should be treated equally on either side (think of it as a low priority operation).
      • And maintaining a compact brackets (parentheses, brackets, braces)
      • Left parenthesis after the function name and its parameter list should be kept compact
      • Sliced ​​or left parenthesis index remains compact
      • A holding extra space on either side of the assignment operator (or otherwise)
      • Do not include spaces on both sides of the equal sign key parameter value or default value of the parameter
      • The equals sign function is defined to be annotated in each insertion space. Further, with a single space after the colon, but also the type of function return value indicates that ->the left and right to insert a space.
      • Discourage the use of compound statements (multiple statements on the same line) idea.

Guess you like

Origin www.cnblogs.com/moxianghuibi/p/11368649.html