decorator
1 |
|
Example 1 保存调试信息
1 | def logged(function): |
Example 2 计时
1 | import time |
generator
1 | def infinite_sequence(): |
argument parsing
1 | import sys |
或者
1 | import sys |
encapsulation
没有直接范围隐藏数据成员
1 | class Person: |
Type hinting
使用mypy做类型检查
1 | mypy .\test.py |
使用显式类型标注
1 | def myfunction(myparameter:int) -> int: |
Magic methods
1 | class Vector: |