Skip to content

Instantly share code, notes, and snippets.

@suhailvs
Last active March 20, 2019 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suhailvs/0876c1393526d6d8a5a153f160ace54a to your computer and use it in GitHub Desktop.
Save suhailvs/0876c1393526d6d8a5a153f160ace54a to your computer and use it in GitHub Desktop.

PEP 8

Yes: import os
     import sys

No:  import sys, os


Yes: spam(ham[1], {eggs: 2})
No:  spam( ham[ 1 ], { eggs: 2 } )

Yes: foo = (0,)
No:  bar = (0, )

Yes: if x == 4: print x, y; x, y = y, x
No:  if x == 4 : print x , y ; x , y = y , x

Yes:   if greeting:
No:    if greeting == True:
Worse: if greeting is True:

Yes: if foo.startswith('bar'):
No:  if foo[:3] == 'bar':

Yes:
def foo(x):
    if x >= 0:
        return math.sqrt(x)
    else:
        return None

No:
def foo(x):
    if x >= 0:
        return math.sqrt(x)

joined_lower for functions, methods, attributes, variables

joined_lower or ALL_CAPS for constants

StudlyCaps for classes

camelCase only to conform to pre-existing conventions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment