Summary of PEP 8

JunePyo Suh·2020년 10월 20일
0

Programming Recommendations

Don't compare boolean values to True or False using the equivalence operator

// Recommended
if my_bool:
  	return ''

Use the fact that empty sequences are falsy in if statements.

// Recommended
my_list = []
if not my_list:
    print('List is empty!')

Don't use if x: when you mean if x is not None

not None and truthy are not equivalent. For instance, empty lists are evaluated as falsy, yet they are not None.

// Recommended
if arg is not None:
	// Do something

// Not recommended
if arg:
	// Do something

Indentation

Four spaces > tab

White spaces

No trailing whitspace immediately inside parentheses, brackets, or braces

// recommended
my_list = [1, 2, 3]

// Not recommended
my_list = [ 1, 2, 3, ]

Between a trailing comma and a closing parenthesis

// recommended
tuple = (1,)

// Not recommended
tuple = (1, )

0개의 댓글