PEP 8
PEP 8 -- Style Guide for Python Code.
Introduction
This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.
This document and PEP 257 (Docstring Conventions) were adapted from Guido's original Python Style Guide essay, with some additions from Barry's style guide.
This style guide evolves over time as additional conventions are identified and past conventions are rendered obsolete by changes in the language itself.
Many projects have their own coding style guidelines. In the event of any conflicts, such project-specific guides take precedence for that project.
Programming Recommendations
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.
Don't compare boolean values to True or False using ==
.
Test for membership should be 'not in'
E731: do not assign a lambda expression, use a def
요약하면,
- 람다 표현식은 익명 함수를 만들어내기 때문에 나중에 에러 트레이스백을 받아볼 때 출처를 파악하기 귀찮아진다.
- 코드를 간결하게 표현하기 위해 다른 표현식에 람다 표현식을 임베딩 하는 것 정도는 괜찮다.
- 하지만 람다 표현식을 만들어 변수 대입을 하는 건 def 에 비해 단 하나의 이점도 없다.