Skip to content

Commit b040466

Browse files
authored
small updates on lesson1
edited by Yimeng Zhang
1 parent 4d1edf3 commit b040466

File tree

1 file changed

+84
-22
lines changed

1 file changed

+84
-22
lines changed

python_basic/python_basic_lesson_01.ipynb

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"collapsed": true
7+
},
68
"source": [
79
"# Lesson 1\n",
8-
"\n",
910
"Python Basic, Lesson 1, v1.0.1, 2016.12 by David.Yi\n",
1011
"\n",
12+
"Python Basic, Lesson 1, v1.0.2, 2017.02 modified by Eamon.Zhang\n",
1113
"\n",
1214
"### 本次内容要点\n",
1315
"\n",
@@ -18,12 +20,15 @@
1820
" * jupyter 和 notebook介绍\n",
1921
"* 基本变量概念\n",
2022
"* print() 和 input() 用法\n",
21-
"* pycharm 用法介绍"
23+
"* pycharm 用法介绍\n",
24+
"\n"
2225
]
2326
},
2427
{
2528
"cell_type": "markdown",
26-
"metadata": {},
29+
"metadata": {
30+
"collapsed": true
31+
},
2732
"source": [
2833
"### python 简介\n",
2934
"\n",
@@ -44,7 +49,11 @@
4449
"\n",
4550
"Python 2.0于2000年10月16日发布,增加了实现完整的垃圾回收,并且支持Unicode。同时,整个开发过程更加透明,社区对开发进度的影响逐渐扩大。目前2系列的最新版本是 2.7.12,2.7版本将在2020年被停止支持。\n",
4651
"\n",
47-
"Python 3.0于2008年12月3日发布,此版不完全兼容之前的Python源代码。不过,很多新特性后来也被移植到旧的Python 2.6/2.7版本。目前3系列版本是3.5.2,3.6已经在 beta 测试中。\n",
52+
"Python 3.0于2008年12月3日发布,此版不完全兼容之前的Python源代码。不过,很多新特性后来也被移植到旧的Python 2.6/2.7版本。目前最新版本是3.6.0,发布于2016年12月。\n",
53+
"\n",
54+
"#### Python能做什么?\n",
55+
"\n",
56+
"![](imgs/python_use.jpg)\n",
4857
"\n",
4958
"#### 设计哲学\n",
5059
"\n",
@@ -62,7 +71,9 @@
6271
},
6372
{
6473
"cell_type": "markdown",
65-
"metadata": {},
74+
"metadata": {
75+
"collapsed": true
76+
},
6677
"source": [
6778
"### 准备工作\n",
6879
"\n",
@@ -136,7 +147,9 @@
136147
},
137148
{
138149
"cell_type": "markdown",
139-
"metadata": {},
150+
"metadata": {
151+
"collapsed": true
152+
},
140153
"source": [
141154
"### 基本变量概念\n",
142155
"\n",
@@ -158,14 +171,15 @@
158171
"outputs": [],
159172
"source": [
160173
"counter = 100 # 整型变量\n",
161-
"miles = 1000.0 # 浮点型\n",
174+
"miles = 1000.0 # 浮点型(小数)\n",
162175
"name = \"John\" # 字符串\n",
163-
"name2 = 'Tom'"
176+
"name2 = 'Tom'\n",
177+
"bool = True # 布尔值"
164178
]
165179
},
166180
{
167181
"cell_type": "code",
168-
"execution_count": 20,
182+
"execution_count": 1,
169183
"metadata": {
170184
"collapsed": false
171185
},
@@ -214,7 +228,7 @@
214228
},
215229
{
216230
"cell_type": "code",
217-
"execution_count": 21,
231+
"execution_count": 2,
218232
"metadata": {
219233
"collapsed": false
220234
},
@@ -234,6 +248,44 @@
234248
"print(a,b)"
235249
]
236250
},
251+
{
252+
"cell_type": "markdown",
253+
"metadata": {},
254+
"source": [
255+
"#### 动态语言\n",
256+
"Python是动态语言,即变量本身的类型不固定\n",
257+
"\n",
258+
"与之对应的静态语言(如Java),在定义变量时,必须先指定变量类型,赋值时如不匹配则报错"
259+
]
260+
},
261+
{
262+
"cell_type": "markdown",
263+
"metadata": {},
264+
"source": [
265+
"#### 理解Python变量在内存中的表示\n",
266+
"当我们输入 a = 'yimeng' 时,Python解释器做了2件事情:\n",
267+
"\n",
268+
"1 在内存中创建了一个'yimeng'的字符串;\n",
269+
"\n",
270+
"2 在内存中创建了一个名为a的变量,并把它指向'yimeng'。\n",
271+
"\n",
272+
"也可以把一个变量a赋值给另一个变量b,这个操作实际上是把变量b指向变量a所指向的数据"
273+
]
274+
},
275+
{
276+
"cell_type": "code",
277+
"execution_count": 2,
278+
"metadata": {
279+
"collapsed": false
280+
},
281+
"outputs": [],
282+
"source": [
283+
"a = 'ABC'\n",
284+
"b = a\n",
285+
"a = 'XYZ'\n",
286+
"#print(b)"
287+
]
288+
},
237289
{
238290
"cell_type": "markdown",
239291
"metadata": {},
@@ -277,7 +329,7 @@
277329
},
278330
{
279331
"cell_type": "code",
280-
"execution_count": 22,
332+
"execution_count": 3,
281333
"metadata": {
282334
"collapsed": false
283335
},
@@ -298,7 +350,7 @@
298350
},
299351
{
300352
"cell_type": "code",
301-
"execution_count": 1,
353+
"execution_count": 3,
302354
"metadata": {
303355
"collapsed": false
304356
},
@@ -321,7 +373,7 @@
321373
},
322374
{
323375
"cell_type": "code",
324-
"execution_count": 2,
376+
"execution_count": 4,
325377
"metadata": {
326378
"collapsed": false
327379
},
@@ -339,12 +391,15 @@
339391
"6\n",
340392
"7\n",
341393
"8\n",
342-
"9\n"
394+
"9\n",
395+
"10\n",
396+
"11\n",
397+
"12\n"
343398
]
344399
}
345400
],
346401
"source": [
347-
"for i in range(10):\n",
402+
"for i in range(13):\n",
348403
" print(i)"
349404
]
350405
},
@@ -397,7 +452,7 @@
397452
},
398453
{
399454
"cell_type": "code",
400-
"execution_count": 13,
455+
"execution_count": 5,
401456
"metadata": {
402457
"collapsed": false
403458
},
@@ -406,19 +461,26 @@
406461
"name": "stdout",
407462
"output_type": "stream",
408463
"text": [
464+
"hello from English\n",
409465
"hello from English\n"
410466
]
411467
}
412468
],
413469
"source": [
414-
"# 更加好,更加 pythonic 的写法\n",
470+
"# 更加好,更加 pythonic 的写法:format函数-增强的格式化字符串函数\n",
471+
"# 关于format的更多细节,参见 https://docs.python.org/3/library/string.html#format-string-syntax\n",
472+
"# 通过关键字传参\n",
473+
"print('{greet} from {language}'.format(greet='hello', language='English'))\n",
415474
"\n",
416-
"print('{greet} from {language}'.format(greet='hello', language='English'))"
475+
"# 通过位置传参\n",
476+
"print('{0} from {1}'.format('hello', 'English'))"
417477
]
418478
},
419479
{
420480
"cell_type": "markdown",
421-
"metadata": {},
481+
"metadata": {
482+
"collapsed": true
483+
},
422484
"source": [
423485
"---\n",
424486
"\n",
@@ -518,7 +580,7 @@
518580
"metadata": {
519581
"anaconda-cloud": {},
520582
"kernelspec": {
521-
"display_name": "Python [default]",
583+
"display_name": "Python 3",
522584
"language": "python",
523585
"name": "python3"
524586
},
@@ -532,7 +594,7 @@
532594
"name": "python",
533595
"nbconvert_exporter": "python",
534596
"pygments_lexer": "ipython3",
535-
"version": "3.5.2"
597+
"version": "3.5.1"
536598
}
537599
},
538600
"nbformat": 4,

0 commit comments

Comments
 (0)