Our recommendation closely follows the PEP 8 Style Guide for Python Code. Note that such coding conventions are only rough guidelines, and specific projects may follow other conventions. Use the guidelines only if there are no reasons to do something else. In the following, we list a couple of general conventions:
Use '
instead of "
for strings
x = 'string' # good
x = "string" # bad
Use spaces after commas
x = [1, 2, 3] # good
x = [1,2,3] # bad
Use no space before or after brackets
x = range(1, 10, 2) # good
x = range( 1, 10, 2 ) # bad
Use under_score
instead of CamelCase
or mixedCase
for variable names and function names.
my_variable = 1 # good
myVariable = 1 # bad
Use spaces around =
in assignments of variables.
x = 1 # good
x=1 # bad
Don't use spaces around =
in assignments of parameters.
x = dict(a=1) # good
x = dict(a = 1) # bad
Use spaces around operators like +
, -
, *
, /
, etc.
x = 1 + 2 # good
x = 1+2 # bad