PEP8¶
1. Python code indented with 4 spaces.¶
4. Type comparison.¶
- Don’t
if type(c) is type type(a):
- Good
import types
if isinstance(c, types.ListType)
5. Only use the is operator to check the exact identity of two references.¶
if some_list is None:
do_somthing_with_the_list()
6. Duck Type¶
In Python, it will not check the type before execute, and also python don’t recommand to do that, for example below:
sorted([1,2,3])
sorted({1,2,3})
sorted({"k1":1, "k2":2, "k3":3})