Repository navigation
Expand file tree
/
Copy path2-python.html
More file actions
611 lines (285 loc) · 21.4 KB
/
Copy path2-python.html
File metadata and controls
611 lines (285 loc) · 21.4 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>2.2 Python 介绍 · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="3-python-syntax.html" />
<link rel="prev" href="1-data-engineering-intro.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
介绍
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../1.Kickoff/">
<a href="../1.Kickoff/">
KickOff Party
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../1.Kickoff/1-teaching-goals.html">
<a href="../1.Kickoff/1-teaching-goals.html">
1.1 教学目的
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../1.Kickoff/2-software-tool.html">
<a href="../1.Kickoff/2-software-tool.html">
1.2 软件和工具
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="../1.Kickoff/3-pre-homework.html">
<a href="../1.Kickoff/3-pre-homework.html">
1.3 课前自学
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="./">
<a href="./">
Python 简介
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="1-data-engineering-intro.html">
<a href="1-data-engineering-intro.html">
2.1 数据工程介绍
</a>
</li>
<li class="chapter active" data-level="1.3.2" data-path="2-python.html">
<a href="2-python.html">
2.2 Python 介绍
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="3-python-syntax.html">
<a href="3-python-syntax.html">
2.3 Python 语法
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="4-python-request.html">
<a href="4-python-request.html">
2.4 HTTP
</a>
</li>
<li class="chapter " data-level="1.3.5" data-path="5-python-syntax-advanced.html">
<a href="5-python-syntax-advanced.html">
2.5 Python 语法进阶
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="../3.Crawler/">
<a href="../3.Crawler/">
爬虫
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="../3.Crawler/1-python-html.html">
<a href="../3.Crawler/1-python-html.html">
3.1 HTML
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="../3.Crawler/4-full-site-crawler.html">
<a href="../3.Crawler/4-full-site-crawler.html">
3.2 爬虫实战
</a>
</li>
<li class="chapter " data-level="1.4.3" data-path="../3.Crawler/3-python-json.html">
<a href="../3.Crawler/3-python-json.html">
3.3 选学:JSON 简介
</a>
</li>
<li class="chapter " data-level="1.4.4" data-path="../3.Crawler/2-login-and-js-render.html">
<a href="../3.Crawler/2-login-and-js-render.html">
3.4 选学:爬虫的难点
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="../4.Processing/">
<a href="../4.Processing/">
数据处理
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../4.Processing/1-data-processing.html">
<a href="../4.Processing/1-data-processing.html">
4.1 初见数据处理
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../4.Processing/2-data-practice.html">
<a href="../4.Processing/2-data-practice.html">
4.2 数据处理应用实例
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../4.Processing/3-pandas.html">
<a href="../4.Processing/3-pandas.html">
4.3 选学:Pandas
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../4.Processing/4-ocr.html">
<a href="../4.Processing/4-ocr.html">
4.4 选学:光学字符识别
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="../project.html">
<a href="../project.html">
大作业和分享
</a>
</li>
<li class="chapter " data-level="1.7" data-path="../learning-suggestions.html">
<a href="../learning-suggestions.html">
后续学习建议
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >2.2 Python 介绍</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="python-简介">Python 简介</h1>
<p>Python 是计算机入门首选语言之一,编写简单,有丰富的生态系统和库,在很多行业和学科都有出色的表现。当前的稳定版本是 3.7。</p>
<p>运行 Python 程序需要 Python 解释器(其实是编译+执行)。</p>
<blockquote>
<p><strong>Task for Tutors</strong>:</p>
<ul>
<li>解释什么是解释器</li>
<li>解释什么是编译</li>
<li>解释什么是执行</li>
</ul>
</blockquote>
<h2 id="第一个-python-程序">第一个 Python 程序</h2>
<ol>
<li><p>使用IDE Anaconda打开 spyder</p>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fwic0c9oomj310y0m4785.jpg" alt="image-20181023182654100"></p>
</li>
<li><p>新建python文件:</p>
<ul>
<li>点击 spyder 右上角第一个图标</li>
<li>或者,使用快捷键( Mac :CMD + n; Windows :ctrl + n)</li>
</ul>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fwic35u3eqj30kh03hwf3.jpg" alt="image-20181023182937635"></p>
</li>
<li><p>我们先看看spyder的界面,spyder包含多个单独的窗口(标有红色方框),每个窗口都有赞成的标签(标有绿色圆框)</p>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fwichbrto1j30va0nvwhv.jpg" alt="image-20181023183934643"></p>
</li>
<li><p>在编辑器中输入<code>import this</code></p>
</li>
<li><p>保存Python文件(注意Python文件都是以 <code>.py</code>结尾的文件):</p>
<blockquote>
<p>Task for Learners:请使用搜索引擎搜索<a href="https://www.bing.com/search?q=python%E6%96%87%E4%BB%B6%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&qs=n&form=QBRE&sp=-1&pq=python%E6%96%87%E4%BB%B6%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83&sc=0-12&sk=&cvid=B1875E99BD0E444FA38C9A35911A955A" target="_blank">「Python文件命名规范」</a>,随意阅读几篇介绍Python命名规范的文章。</p>
</blockquote>
<ul>
<li>点击 spyder 右上角第三个图标</li>
<li>或者,使用快捷键( Mac :CMD + s; Windows :ctrl + s)
<img src="https://ws3.sinaimg.cn/large/006tNbRwly1fwic69r6aoj30kh03haao.jpg" alt="image-20181023183230195"></li>
</ul>
</li>
<li><p>运行Python文件:</p>
<ul>
<li>点击 spyder 右上角第七个图标</li>
<li>或者,使用快捷键( Mac :F5; Windows :F5)</li>
</ul>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fwid2kg2f3j30vb0nv795.jpg" alt="Spyder__Python_3_6_"></p>
</li>
</ol>
<p>可以看到 Python 的哲学,描述于一首诗中。上面的代码中,<code>import</code> 语句的作用是引入一个包,而这个包 <code>this</code> 的作用是打印这首诗。</p>
<h2 id="编程">编程</h2>
<h3 id="任务分解">任务分解</h3>
<p>编程的第一步就是把要做的事情,分解成一步一步,用计算机语言讲清楚,让计算机可以执行。</p>
<h3 id="编程思维">编程思维</h3>
<p><img src="https://ws4.sinaimg.cn/large/006tNbRwly1fwict5oyqdj31kw1kw124.jpg" alt="图片来于[Computational Thinking:Decomposition | Abstraction | Patterns | Algorithms](https://www.computationalthinkers.com/product/computationalthinking/)"></p>
<p>Donald Knuth 说过:一个人并不真正了解一件事,除非他把一件事教给计算机 —— 特别是用算法把它描述出来。</p>
<blockquote>
<p>It has often been said that a person does not really
understand something until he teaches it to someone else.
Actually a person does not really understand something
until after teaching it to a computer, i.e., express it
as an algorithm.</p>
</blockquote>
<p><strong>Learning by Additional Reading</strong>: <a href="https://edu.google.com/resources/programs/exploring-computational-thinking/" target="_blank">Google for Education: Computational Thinking</a> (需要科学上网,拓展阅读,非本工作坊所需)</p>
<h2 id="程序出错">程序出错</h2>
<p>有一个说法叫:计算机很笨却听话(The computer is very dumb but obedient)。当遇到语法错误时,即使是很微小的错误,它也不会自己修正它。程序员每天都会遇到很多各种语法错误。只要仔细阅读错误信息,找到并修正就可以了。</p>
<p><strong>Learning by Additional Reading</strong>: <a href="http://guyhaas.com/bfoit/Intro_to_Programming/Programming.html" target="_blank">Introduction to Computer Programming - What Is It</a> </p>
<h2 id="打印一段话">打印一段话</h2>
<p><strong>Learning by Doing</strong>: </p>
<p>Python 的 <code>print</code> 函数不是打印到纸上,而是打印到屏幕上(确切来说是标准输出流)</p>
<pre><code>print("I can program!")
</code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="1-data-engineering-intro.html" class="navigation navigation-prev " aria-label="Previous page: 2.1 数据工程介绍">
<i class="fa fa-angle-left"></i>
</a>
<a href="3-python-syntax.html" class="navigation navigation-next " aria-label="Next page: 2.3 Python 语法">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"2.2 Python 介绍","level":"1.3.2","depth":2,"next":{"title":"2.3 Python 语法","level":"1.3.3","depth":2,"path":"2.Python/3-python-syntax.md","ref":"2.Python/3-python-syntax.md","articles":[]},"previous":{"title":"2.1 数据工程介绍","level":"1.3.1","depth":2,"path":"2.Python/1-data-engineering-intro.md","ref":"2.Python/1-data-engineering-intro.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"2.Python/2-python.md","mtime":"2018-10-24T04:05:54.743Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-26T09:28:27.553Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>