1. Variables
Constants are usually defined on a module level and written in all capital letters with underscores separating words, e.g.,
MAX_OVERFLOW
.arguments. Always use
self
for the first argument to instance methods and usecls
for the first argument to class methods (@classmethod
).
2. Others
Function should be lowercase with words separated by underscores as necessary to improve readability. PS: mixedCase is allowed only in contexts where that's already the prevailing style (e.g.
threading.py
) to retain backwards compatibility.Exception should use the suffix
Error
(if the exception actually is an error), such asZeroDivisionError
. The class naming convention applies here because exceptions should be classes.