Best Practices
PEP 8 Style Guide
Python code style conventions every developer should know
Interview: Code quality — expected at all levels
PEP 8
PEP 8 is the official style guide for Python code. Following it ensures consistency across teams and projects.
Key Rules
- Indentation: 4 spaces per level (never tabs)
- Line length: 79 characters (88 for Black-formatted code)
- Imports: Grouped and sorted — stdlib, third-party, local
- Naming:
snake_casefor functions/variables,PascalCasefor classes,UPPER_CASEfor constants - Whitespace: One space around operators, after commas; no trailing whitespace