-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorepython-reading-notes-how-day4.html
More file actions
194 lines (148 loc) · 7.43 KB
/
corepython-reading-notes-how-day4.html
File metadata and controls
194 lines (148 loc) · 7.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="HandheldFriendly" content="True" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,400;0,700;1,400&family=Source+Sans+Pro:ital,wght@0,300;0,400;0,700;1,400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/stylesheet/style.min.css">
<link id="pygments-light-theme" rel="stylesheet" type="text/css"
href="https://blog.tonychow.me/theme/pygments/colorful.min.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/fontawesome.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/brands.css">
<link rel="stylesheet" type="text/css" href="https://blog.tonychow.me/theme/font-awesome/css/solid.css">
<link href="https://blog.tonychow.me/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Tonychow's Blog Atom">
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#333333">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#333333">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Microsoft EDGE -->
<meta name="msapplication-TileColor" content="#333333">
<meta name="author" content="tonychow" />
<meta name="description" content="" />
<meta name="keywords" content="corepython, reading-notes, python">
<meta property="og:site_name" content="Tonychow's Blog"/>
<meta property="og:title" content="Python 核心编程读书笔记 Day4"/>
<meta property="og:description" content=""/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="https://blog.tonychow.me/corepython-reading-notes-how-day4.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2014-07-15 00:00:00+08:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="https://blog.tonychow.me/author/tonychow.html">
<meta property="article:section" content="readings"/>
<meta property="article:tag" content="corepython"/>
<meta property="article:tag" content="reading-notes"/>
<meta property="article:tag" content="python"/>
<meta property="og:image" content="/images/avatar.jpg">
<title>Tonychow's Blog – Python 核心编程读书笔记 Day4</title>
</head>
<body class="light-theme">
<aside>
<div>
<a href="https://blog.tonychow.me/">
<img src="/images/avatar.jpg" alt="" title="">
</a>
<h1>
<a href="https://blog.tonychow.me/"></a>
</h1>
<p>Go/Python backend developer</p>
<ul class="social">
<li>
<a class="sc-github" href="https://github.com/chow1937" target="_blank">
<i class="fab fa-github"></i>
</a>
</li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="https://blog.tonychow.me/">Home</a>
<a href="/archives.html">Archives</a>
<a href="/categories.html">Categories</a>
<a href="/tags.html">Tags</a>
<a href="https://blog.tonychow.me/feeds/all.atom.xml">Atom</a>
</nav>
<article class="single">
<header>
<h1 id="corepython-reading-notes-how-day4">Python 核心编程读书笔记 Day4</h1>
<p>
Posted on 二 15 七月 2014 in <a href="https://blog.tonychow.me/category/readings.html">readings</a>
• 1 min read
</p>
</header>
<div>
<p>今天的主要阅读了 10-12 章的内容,这三章内容主要涉及异常,函数及模块,这几个模块
也是 Python 中比较重要的基本内容,也有相对于其他语言的独特之处,下面继续总结今
天的阅读笔记。</p>
<h3>第十章:错误和异常</h3>
<p>本章关注的内容是异常。异常在其他语言中也有实现,一般来说,异常处理给程序员提供
了一种在错误发生的时候对错误进行处理的方式。与其出现错误的时候,直接终止程序的
执行,不如对错误进行处理之后让程序继续执行。下面是本章要点:</p>
<p>1.错误引发异常的时候会打断正常的程序处理流程;</p>
<p>2.Python 异常的检测可以通过 try 语句进行,通常有 try-excetpt,try-finally模式;</p>
<p>3.try 语句可以带多个 except ,可以处理多种异常,也可以直接多个异常放在一个元组
中;</p>
<p>4.except Exception[, reason];</p>
<p>5.try-except 同样也支持 else 子句,不发生异常则执行 else 子句的语句;</p>
<p>6.实现了 <code>__enter_</code> 和 <code>__exit__</code> 方法的类可以利用 with 语句;</p>
<p>7.<code>__exit__</code> 具有三个参数,exc_type, exc_value, exc_traceback;</p>
<h3>第十一章:函数和函数式编程</h3>
<p>函数在 Python 中其实也是一个对象,保存了函数的相关内容,所以在 Python 中,函
数也和普通的对象一样,可以传给一个函数,也可以作为函数的返回值返回,因此也导
至了 Python 支持一部分函数式编程的特性。以下是要点:</p>
<p>1.Python 中的函数即使没有 return 语句,也会默认返回值为 None;</p>
<p>2.Python 中支持默认参数,但是非默认参数需要在默认参数前;</p>
<p>3.Python 中函数支持将参数放进元组或者字典中;</p>
<p>4.<code>func(*args)</code> 的形式是将参数放到元组中;</p>
<p>5.<code>func(**kwargs)</code> 的形式是将参数放到字典中,表示的是应对参数名及其值;</p>
<p>6.Python 支持在函数内部定义函数,并且内部函数可以调用包含函数的局部变量;</p>
<p>7.函数内部是一个局部空间;</p>
<p>8.装饰器函数接受一个函数返回另外一个装饰后的函数;</p>
<p>9.装饰器利用 <code>@</code> 来装饰函数,相当于:<code>foo = deco(foo)</code>;</p>
</div>
<div class="tag-cloud">
<p>
<a href="https://blog.tonychow.me/tag/corepython.html">corepython</a>
<a href="https://blog.tonychow.me/tag/reading-notes.html">reading-notes</a>
<a href="https://blog.tonychow.me/tag/python.html">python</a>
</p>
</div>
</article>
<footer>
<p>
© 2017 - This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/deed.en_US" target="_blank">Creative Commons Attribution-ShareAlike</a>
</p>
<p>
Built with <a href="http://getpelican.com" target="_blank">Pelican</a> using <a href="http://bit.ly/flex-pelican" target="_blank">Flex</a> theme
</p><p>
<a rel="license"
href="http://creativecommons.org/licenses/by-sa/4.0/"
target="_blank">
<img alt="Creative Commons License"
title="Creative Commons License"
style="border-width:0"
src="https://i.creativecommons.org/l/by-sa/4.0/80x15.png"
width="80"
height="15"/>
</a>
</p> </footer>
</main>
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Blog",
"name": " Tonychow's Blog ",
"url" : "https://blog.tonychow.me",
"image": "/images/avatar.jpg",
"description": "tonychow's Thoughts and Writings"
}
</script>
</body>
</html>