Python Coding Style Cheat-Sheet

Contents

[TOC]

Introduction

This cheat-sheet for Python coding conventions is based on the PEP 8 official style guide.

Line Length and Indentation

Naming Conventions

Comments

Whitespace

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.

Docstrings

Imports

Blank Lines


This guide was generated by Google Gemini and edited by Brian Bird 10/2/2025