Python Tutorial Series – Style Guide

A best practice in programming is to adhere to a consistent style guide. It allows for more readable code and easier maintenance. Python actually has it’s own suggested style guide. It is online at: https://www.python.org/dev/peps/pep-0008/.
Some highlights include:

– Indentation is 4 spaces – This is really important. If a file has a line with incorrect indentation, an error will be thrown when running the file.
– Add a line break before binary operators.
– Imports should be on separate lines.
– Pick either single quotes or double quotes and stick with it.
– Surround binary operators with a space on each side.
– Avoid spaces inside braces, brackets and parentheses.
– Avoid trailing whitespace.
– Modules should have short, all lowercase names, separated by underscores for multi-word names.
– Class names and type variable names should have each word start with a capital letter, ex: ClassName.
– Function and variable names should be all lowercase with each word separated by an underscore, ex: my_function.
– Constants should be all capitalized with each word separated by an underscore, ex: THREE = “three”.