PEP8 - the fashion šŸ’ƒ police of Python

Posted on 22 Jun, 2019

Well basically PEP8 is a style guide which provides guidelines and best practices for writing python code.

How I learn?

Well bascially the official Python docs for PEP8 seems good but I use pep8.org. It provides much more cleaner interface.

Summary

Below is a summary which includes some go-to rules you can memorize.

  1. Use 4 spaces per indentation level.

  2. Limit all lines to a maximum of 79 characters. Use \ to break/continue line.

  3. Never use the characters ā€˜lā€™ (lowercase letter el), ā€˜Oā€™ (uppercase letter oh), or ā€˜Iā€™ (uppercase letter eye) as single character variable names. These are misunderstood with numerals one and zero in some font styles.

  4. Function Names - lowercase words separated by _ .

  5. Class Names - Start each word with a capital letter. Use CamelCase E.g StudentClass

Tools

If use Sublime Text, you can install Python PEP8 Autoformat - it does the job for you.

Last updated