What's PEP 8?

It contains some conventions in coding with Python. They make the codes clearer and more beautiful. Read the full doc here. Below are just some of them in my choice.

Naming styles

Code layout

Indentation

Use 4 spaces per indentation level. Note that, in this site, for a better view, I use 2 spaces for the code highlight.

# YES
def func(...):
    commands # 4 spaces
# NO
def func(...):
  commands # 2 spaces

Vertical align when break a continuous line:

# YES
foo = long_function_name(var_one, var_two,
                         var_three, var_four)
# NO
foo = long_function_name(var_one, var_two,
    var_three, var_four)

Distinguish arguments from the rest:

# YES
def long_function_name(
        var_one, var_two, var_three,
        var_four):
    print(var_one)
# NO
def long_function_name(
    var_one, var_two, var_three,
    var_four):
    print(var_one)

Tabs or spaces?

Spaces are preferred. Don't mix tabs and spaces (not allowed in Python 3).

Max line lenght

Max of 79 characters.

Line break with operator