-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorepython-reading-notes-how-day3.html
187 lines (141 loc) · 7.02 KB
/
corepython-reading-notes-how-day3.html
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
<!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 核心编程读书笔记 Day3"/>
<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-day3.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2014-07-13 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 核心编程读书笔记 Day3</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-day3">Python 核心编程读书笔记 Day3</h1>
<p>
Posted on 日 13 七月 2014 in <a href="https://blog.tonychow.me/category/readings.html">readings</a>
• 1 min read
</p>
</header>
<div>
<p>今天阅读的章节是 8 和 9 章,前面的章节已经介绍了 Python 的基本的数据类型,这两章分别介绍了 Python 的条件
循环语句和文件类型。</p>
<h3>第八章:条件和循环</h3>
<p>这章主要就是介绍 Python 中的条件和循环语句,Python 中的条件语句有 if-else,而循环则有 while 和 for。要点:</p>
<p>1.if 语句有 if-else 和 if-elif-elif-else 模式;</p>
<p>2.Python 中也存在条件表达式,和其他语言的不同,是利用 if 实现的:X if C else Y;</p>
<p>3.Python 中的 while 和其他语言的类似,而 for 循环则不一样,for 循环可以遍历可迭代对象;</p>
<p>4.在遍历迭代器的时候,for 循环会调用迭代器的 next 方法,并且在遇到 StopIteration 异常结束遍历;</p>
<p>5.range(start, stop, step=1) 函数可以生成一个列表;</p>
<p>6.sorted 和 zip 函数返回一个列表,而 reversed 和 enumerate 函数则返回一个迭代器;</p>
<p>7.else 同样可以用在 while 和 for 循环语句中,在循环结束后执行,break 则会跳出这个 else;</p>
<p>8.迭代器对象需要实现 next 和 <code>__iter__</code> 方法;</p>
<p>9.列表解释:[expr for iter_var in iterable],返回列表;</p>
<p>10.生成器表达式:(expr for iter_var in iterable);</p>
<h3>第九章:文件和输入输出</h3>
<p>本章主要关注 Python 中的文件对象及输入和输出方面,下面是要点:</p>
<p>1.文件只是连续的字节序列;</p>
<p>2.可以用 open 或者 file 函数打开或者创建文件,这两个函数类似;</p>
<p>3.文件对象的 readlines 方法将会将该文件所有行都加载到内存中,打开大文件不太友好;</p>
<p>4.xreadlines 是以迭代的方式每次读取文件的一行,不过现在可以直接对文件对象进行迭代达到一样的效果;</p>
<p>5.readline 函数不会去除读取到的行的换行符,writelines 也不会自动添加换行符;</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>