Zen of Python
Also know as PEP 20. (PEP is proposal for enhancement)
🪄 Code:
📟 Output:
## Zen of Python (summary)
Readability is very important
10 reads, 1 write
Simple is better than complex
Easier to maintain and upgrade
Motivations:
Beautiful code
"Pythonic way"
Update/clean advises
General advises
Use docstrings in modules and functions, add
README.md
to your projectDon't use inline comments too much - clear code is better than comment.
Split your code into small functions. Ideal length - less than 10 lines.
Variables should be lower-case with underscores
all_lines
and notAllLines
orallLines
.Variables should be named properly with descriptive names(
a
,abc
orfunction_1
are not good).Modules (
.py
files) should be max 500 lines of code.Each module should have a clear purpose and name (e.g.
data_processing.py
,db_export.py
).Use
if __name__ == '__main__':
code blocks if this module will be imported.Use list comprehensions when it is suitable (not too long lines)
Use
for
loops and don't forget aboutcontinue
andbreak/else
clauses.When iterating - don't use
for i in range(len(list_))
, useenumerate()
instead
Last updated