没有合适的资源?快使用搜索试试~ 我知道了~
Intermediate Python
5星 · 超过95%的资源 需积分: 9 44 下载量 90 浏览量
2015-10-26
19:26:33
上传
评论 2
收藏 1.01MB PDF 举报
温馨提示
试读
76页
This is a new python book that introduces some intermediate tech such as advanced function, decorators, generators etc.
资源推荐
资源详情
资源评论
Contents
I Preface 1
II Author 2
1 *args and **kwargs 3
1.1 Usage of *args . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Usage of **kwargs . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Using *args and **kwargs to call a function . . . . . . . . . . . . . 4
1.4 When to use them? . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Debugging 6
3 Generators 8
3.1 Iterable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.4 Generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Map & Filter 12
4.1 1. Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2 2. Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5 set Data Structure 14
i
6 Ternary Operators 16
7 Decorators 18
7.1 Everything in python is an object: . . . . . . . . . . . . . . . . . . 18
7.2 Defining functions within functions: . . . . . . . . . . . . . . . . . 19
7.3 Returning functions from within functions: . . . . . . . . . . . . . 20
7.4 Giving a function as an argument to another function: . . . . . . 21
7.5 Writing your first decorator: . . . . . . . . . . . . . . . . . . . . . 21
7.6 1. Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
7.7 2. Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8 Global & Return 26
9 Mutation 28
10 __slots__ Magic 31
11 Virtual Environment 33
12 Collections 35
12.1 1.defaultdict . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
12.2 2.counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
12.3 3.deque . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
12.4 4.namedtuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
13 Enumerate 41
14 Object introspection 43
14.1 1.dir . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
14.2 2.type and id . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
14.3 3.inspect module . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
15 Comprehensions 45
15.1 list comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . 45
15.2 dict comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . 46
15.3 set comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . 47
16 Exceptions 48
16.1 Handling multiple exceptions: . . . . . . . . . . . . . . . . . . . . 48
17 Lambdas 51
18 One Liners 53
ii
19 For - Else 55
19.1 1.else clause: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
20 Open function 57
21 Targeting Python 2+3 60
22 Coroutines 63
23 Function caching 65
23.1 Python 3.2+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
23.2 Python 2+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
24 Context managers 67
24.1 Implementing Context Manager as a Class: . . . . . . . . . . . . . 68
24.2 Handling exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 69
24.3 Implementing a Context Manager as a Generator . . . . . . . . . 70
iii
iv
剩余75页未读,继续阅读
资源评论
- weixin_407494982019-02-19东西不错 内容不多 但是都比较有用
fatespinner123
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功