[TOC]
This cheat-sheet for Python coding conventions is based on the PEP 8 official style guide.
Indentation: Use 4 consecutive spaces per indentation level and Prefer spaces over tabs.
my_module.py).my_package).MyClass).my_function, my_variable).self for instance methods, cls for class methods.MY_CONSTANT)._my_private_method, _private_variable).__private_attribute).Block Comments: Indent to the same level as the code they describe. Start each line with # followed by a single space. Separate paragraphs with a line containing only #.
# and a single space. Avoid explaining the obvious.Always surround binary operators (assignment, comparison, arithmetic, etc.) with a single space on either side (e.g., a = b + c).
No space between function name and opening parenthesis. No space immediately inside parentheses, brackets, or braces.
Trailing Commas:
Use trailing commas when defining tuples or lists on multiple lines for easier diffs.
"""This is a docstring.""").__future__ imports.import os\nimport sys).import package.module) unless explicitly using relative imports within a package.This guide was generated by Google Gemini and edited by Brian Bird 10/2/2025