What is Python's PEP 8 and code style?
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.