Content:
+ Module vs. Package
+ Clean code 必學技巧
+ Lambda
+ Bad pattern to avoid
Module vs. Package
A module
is a .py
file, a package
is a folder with an __init__.py
file. When you import a package as a module, the contents of __init__.py
module are imported.
A Python module is simply a Python source file, which can expose classes, functions and global variables.
- module = file
- package = directory
Clean code 必學技巧
5 coolest Python features to learn
- list comprehensions
- generator expression
- slice assignment
- iterable unpacking (destructure)
- dictionary comprehensions
list init
list = [False] * len(3) # [False, False, False]
Lambda
<空>
Bad pattern (要避免的 pattern)
ITM (Initialize Then Modify)
- 先宣告後修改
// Initialize
i = 0
for t in X:
// Then Modify
i += 1
- 上例解法: e.g. 改用 enumerate
Reference
[2] Corey schafer. Python OOP Tutorial 1: Classes and Instances. (2016)