This document gives coding conventions for the Python code comprising the standard library in the main Python distribution.
Many projects have their own coding style guidelines. Consistency within one module or function is the most important. Some other good reasons to ignore a particular guideline:  .
In the event of any conflicts, such project-specific guides take precedence for that project. However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When using a hanging indent the following should be considered; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line. foo = long_function_name(var_one, var_two, var_three, var_four) # More indentation included to distinguish this from the rest.
One of Guido's key insights is that code is read much more often than it is written. def long_function_name( var_one, var_two, var_three, var_four): print(var_one) # Hanging indents should add a level.
The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. foo = long_function_name( var_one, var_two, var_three, var_four) # Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two, var_three, var_four) # Further indentation required as indentation is not distinguishable.
def long_function_name( var_one, var_two, var_three, var_four): print(var_one) ), plus a single space, plus an opening parenthesis creates a natural 4-space indent for the subsequent lines of the multiline conditional.This can produce a visual conflict with the indented suite of code nested inside the -statement, which would also naturally be indented to 4 spaces.This PEP takes no explicit position on how (or whether) to further visually distinguish such conditional lines from the nested suite inside the # No extra indentation.if (this_is_one_thing and that_is_another_thing): do_something() # Add a comment, which will provide some distinction in editors # supporting syntax highlighting.if (this_is_one_thing and that_is_another_thing): # Since both conditions are true, we can frobnicate.do_something() # Add some extra indentation on the conditional continuation line.