Python Enhancement Proposal 8 or PEP 8 is a comprehensive styling guide for your Python code. PEP 8’s aim is to bring all Python together under one styling guide. This increases the readability and overall understanding of Python code. PEP 8 is not always meant to be followed in every circumstance. You will run into code that just doesn’t apply and if so then you may need to break away from the style guide for a short instance. The key is the use the style guide whenever you can though. It will help you and everyone else that lay eyes on your code read it and work on it. I will cover the areas that I feel are most important. I will not be going over some areas and others, I may just go over skim over. I really recommend reading PEP 8 in full, as this guide is meant more as a quick overview. To really understand and get more in-depth explanations, as well as parts I have chosen to not include in this article. The sections of PEP 8 I will be going over are as follows:

  • Code Lay-out
  • Strings
  • Whitespace
  • Trailing Commas
  • Comments
  • Naming Conventions
  • Recommendations

Code Lay-out

Indentation:

  • 4 Spaces, although this is up to you on continuation lines, as long as there is some form of indentation.
  • You can line up wrapped elements in parentheses vertically or with a hanging indent.
## 4 space indent
def hello(var):
    print(var)

## vertical alignment
example2 = function(first_var, second_var,
                    third_Var, fourth_var)
## hanging indent
example3 = function(
    first_var, second_var,
    third_var, fourth_var)

#data-science #style-guides #python #code #programming

An Overview of The PEP 8 Style Guide
1.30 GEEK