What is Python's PEP 8 and code style?
Why Interviewers Ask This
Interviewers ask this to evaluate whether you have the depth of knowledge needed to mentor others and lead technical decisions. The expected answer goes beyond definitions into practical implications and real-world consequences.
Answer
PEP 8 is Python's official style guide. Key rules: indentation: 4 spaces (no tabs). Line length: max 79 characters for code, 72 for docstrings. Naming: lower_snake_case for variables/functions, UpperCamelCase for classes, UPPER_SNAKE_CASE for constants, _single_leading for "protected", __double_leading for name mangling. Imports: one per line, grouped (stdlib → third-party → local), alphabetical within groups. Whitespace: spaces around operators, after commas, no spaces inside brackets. Blank lines: 2 between top-level definitions, 1 between methods. Tools: flake8 (linting), black (auto-formatter — enforces a strict, consistent style), isort (import sorter), pylint (comprehensive linter). Modern projects use ruff — an extremely fast linter + formatter written in Rust that replaces flake8, isort, and pyupgrade.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Python candidates.