Write high-quality code: 91 Suggestions for improving Python programs http://book.douban.com/subject/25910544/
1. (recommended) is used to determine whether the ID of two objects is equal, = = is the judgment value is equal
2. (recommended) For,while, and the try statement can be followed by the Else statement, you can simplify the code
3. (recommended) __init__.py module can write code, import only need import package (folder)
4. (recommendation 19) use Import a instead of from a import B to avoid errors caused by nested imports
Try not to use import *
Add return to the 5.finally statement, or break will mask the exception that jumps out, so don't use return and break in finally
7. (recommendation 32) default values for default parameters do not use do not set as mutable objects, such as lists, dictionaries, etc.
8. (recommendation 30) List parsing can be multiple loops,
list1=list2=[1,2,3]
print [(A, B) for a in List1-B in List2 if a==1]
9. (recommendation 30) (1) represents the string (1,) is the ancestor
10. (recommendation 36) string manipulation
Partition method,
Src= ' ABCDEFG '
Print src.partition (' de ') # (' abc ', ' de ', ' FG ')
Split () can have no parameters,
11. (Recommended) Defaultdict
From collections Import Defaultdict
Dict1=defaultdict (list)
dict1[' A '].append (' B ')
No error.
12. (recommendation 39) Counter module for quantity statistics
From collections Import Counter
Writing a high-quality code: 91 Suggestions for improving Python programs