PEP8 is a specification widely used in Python coding, and only the most important part is covered here: from the official website

  • Use 4 Spaces for indentation, not tabs.

    Four Spaces is a good compromise between small indentation (allowing greater nesting depth) and large indentation (making it easier to read). Tabs introduce confusion and are best avoided.

  • Newline, so that a line does not exceed 79 characters.

    This helps users with small monitors and allows multiple code files to be placed side by side on larger monitors.

  • Use empty lines to separate functions from classes and larger code blocks within functions.

  • If possible, put comments on a separate line.

  • Use docstrings.

  • Use Spaces before and after operators and commas, but not directly inside parentheses: A = f(1, 2) + g(3, 4).

  • Name your classes and functions with consistent rules; The convention is to use UpperCamelCase for classes and lowercase_with_underscores for functions and methods and variables. Always name the first method parameter with self (see Exploring classes for more information on classes and methods).

  • If your code is intended for use in an international environment, don’t use fancy coding. Python’s default UTF-8 or plain ASCII will work best in all cases.

  • Also, don’t use non-ASCII characters in your identifiers, even if there’s a small chance that someone who speaks a different language will read or maintain your code.