Show Menu
Cheatography

Python Style Guide Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

General Rules

4 spaces for identation
Maximum line length 79 characters
Line break before binary operators
Content order: Module comments, docstr­ings, imports, module globals, constants

Naming conven­tions

Package / Module
lowercase
Class
CamelCase
Variables
CamelCase
Global Variables
lowerc­ase­_un­der­score
Functions / Methods
lowerc­ase­_un­der­score
private Methods / Instance Variables
Leading _ and then lowerc­ase­_un­der­score
Constants
UPPERC­ASE­_UN­DER­SCORE

Blank lines

Surround top-level functions and
class defini­tions with two blank lines.
Surround Method defini­tions inside a class
by a single blank line.
Extra blank lines may be used (spari­ngly) to separate groups of related functions.
Use blank lines in functions, sparingly, to indicate logical sections.

Imports

Imports should usually be on separate lines
Imports should be grouped in the following order:
 1.standard library imports
 2.related third party imports
 3. local applic­ati­on/­library specific imports
You should put a blank line between each group of imports.
Wildcard imports
(from <mo­dul­e> import *)
should be avoided