Jmds Python Pep8 Style Guide
Jmds Python Pep8 Style Guide
Never use l, O, or I single letter names as O = 2 # This may look Limit the line length of Use complete Make sure to update
these can be mistaken for 1 and 0, like you're trying to comments and sentences, starting comments if you
depending on typeface reassign 2 to zero docstrings to 72 with a capital change your code.
Use 4 consecutive spaces to indicate indentation. Use .startswith() and .endswith() instead of slicing.
Surround top-level functions and classes with two blank lines > ]
Surround method definitions inside classes with a single blank line. 2 - Line up the closing brace with the first character of the line that
starts the construct:
Use blank lines sparingly inside functions to show clear steps.
list_of_numbers = [
1, 2, 3,
Indentation Following Line Breaks
4, 5, 6,
There are two styles of indentation you can use. 7, 8, 9
The first of these is to align the indented block with the opening ]
delimiter:
An alternative style of indentation following a line break is a hanging Documentation Strings
indent. This is a typographical term meaning that every line but the Surround docstrings with three double quotes on either side, as in
first in a paragraph or statement is indented. """This is a docstring""".
Write them for all public modules, functions, classes, and methods.
Indentation Following Line Breaks 2
Put the """ that ends a multiline docstring on a line by itself:
def function(arg_one, arg_two,
For one-line docstrings, keep the """ on the same line:
arg_three, arg_four):
return arg_one
Whitespace Around Binary Operators
x = 5
Surround the following binary operators with a single space on either
if (x > 3 and
side:
x < 10):
Assignment operators (=, +=, -=, Comparisons (==, Booleans
print(x)
and so forth) !=, >, <. >=, <=) and (and, not,
x = 5
(is, is not, in, not in) or)
if (x > 3 and
x < 10): When = is used to assign a def function(default_paramet‐
default value to a function er=5):
# Both conditions satisfied
argument, do not surround it with
print(x)
spaces.
x = 5
if (x > 3 and y = x**2 + 5 z = (x+y) * (x-y)