PEP8 - the fashion 💃 police of Python
📅️ Published: June 22, 2019 • 🕣 1 min read
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.
Below is a summary which includes some go-to rules you can memorize.
- Use 4 spaces per indentation level.
- Spaces are preferred instead of tabs (Why ?? :disappointed_relieved:) Python disallows mixing of Tabs & Spaces (Syntax Errors). So be consistent with what you choose, I prefer tabs :wink:
- Limit all lines to a maximum of 79 characters. Use \ to break/continue line.
- 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.
- Function Names - lowercase words separated by _ .
- Class Names - Start each word with a capital letter. Use CamelCase E.g StudentClass
If use Sublime Text, you can install Python PEP8 Autoformat - it does the job for you.