Python has styling conventions. These styling conventions are defined in the Python Enhancement Proposals (PEP8). Here are the condensed version of the rules:
-
Indentation should be done using spaces and not tabs.
-
Indentation is done using 4 spaces.
-
Python files are UTF-8 encoded.
-
80 columns is the maximum for code per line.
-
Each statement is to be written on a line of its own.
-
Variable names, function names, and filenames are all written in lowercase. Underscores are used when separating words (aka snake_case).
-
The names of classes are capitalized. If the name of a class is more than one word, use CamelCase.
-
The names of packages are written in lowercase and no underscore is needed at all.
-
Variables that are constants are written in uppercase.
-
Make sure that variables have names that have meaning (e.g. get_user).
-
Leave a space when dealing with operators (e.g. a + b).
-
Whitespace that is unnecessary should be removed.
-
Leave a blank line before writing a function.
-
When writing methods in a class leave a blank line between them.
-
Make sure to use blank lines inside functions and methods in order to keep related blocks of code separate and make your code more readable.