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.
Package & module names & function & variable: all_lower_case
or short
with underscore
.
Class names: use CapWords
.
Constant: ALL_CAPITAL_LETTERS
.
Avoid these:
l = 1 # lowercase letter el
O = 1 # uppercase letter oh
I = 1 # uppercase letter eye
Capitalized_Words_With_Underscores = 1 # ugly
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)
Spaces are preferred. Don't mix tabs and spaces (not allowed in Python 3).
Max of 79 characters.