diff --git a/1. Python 安装及基本语法.ipynb b/1. Python 安装及基本语法.ipynb
index b9d884d..eb97719 100644
--- a/1. Python 安装及基本语法.ipynb
+++ b/1. Python 安装及基本语法.ipynb
@@ -2,7 +2,6 @@
"cells": [
{
"cell_type": "markdown",
- "id": "boxed-account",
"metadata": {},
"source": [
"# Python 安装及基本语法"
@@ -10,7 +9,6 @@
},
{
"cell_type": "markdown",
- "id": "equal-nicholas",
"metadata": {},
"source": [
"Python 是一种上手简单、功能丰富的编程语言,是数据科学领域首选的可靠工具。通过 Python 你可以迅速解决问题,而不是把精力消耗在复杂的语法与编程细节上,这与本教程的核心思想“简洁”不谋而合。\n",
@@ -20,7 +18,6 @@
},
{
"cell_type": "markdown",
- "id": "suitable-islam",
"metadata": {},
"source": [
"## 1.1.1 Python 安装运行"
@@ -28,7 +25,6 @@
},
{
"cell_type": "markdown",
- "id": "located-orientation",
"metadata": {},
"source": [
"### 1.1.1.1 下载安装"
@@ -36,7 +32,6 @@
},
{
"cell_type": "markdown",
- "id": "satisfied-contrast",
"metadata": {},
"source": [
"- 对于 Windows / Mac 用户,首先在官网 https://www.python.org/downloads/ 下载对应操作系统的 Python3 安装包,然后双击运行安装。\n",
@@ -46,7 +41,6 @@
},
{
"cell_type": "markdown",
- "id": "organic-marshall",
"metadata": {},
"source": [
"在安装完成后,打开命令提示符(win + R键,输入cmd回车) / 终端(command + 空格,输入term回车),执行 python3 -V 命令,若出现对应python版本号则安装成功。"
@@ -54,15 +48,13 @@
},
{
"cell_type": "markdown",
- "id": "advisory-agenda",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "reduced-centre",
"metadata": {},
"source": [
"### 1.1.1.2 编辑器与解释器\n"
@@ -70,7 +62,6 @@
},
{
"cell_type": "markdown",
- "id": "seventh-television",
"metadata": {},
"source": [
"一个 Python 程序要经过“编写”和“运行”两个阶段。\n",
@@ -85,7 +76,6 @@
},
{
"cell_type": "markdown",
- "id": "legislative-quick",
"metadata": {},
"source": [
"### 1.1.1.3 第一个Python程序"
@@ -93,7 +83,6 @@
},
{
"cell_type": "markdown",
- "id": "becoming-fleece",
"metadata": {},
"source": [
"在成功安装后,我们将尝试编写第一个Python程序。\n",
@@ -107,15 +96,13 @@
},
{
"cell_type": "markdown",
- "id": "other-cosmetic",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "extraordinary-crazy",
"metadata": {},
"source": [
"下一步我们尝试用解释器运行保存的.py程序。\n",
@@ -127,15 +114,13 @@
},
{
"cell_type": "markdown",
- "id": "essential-verification",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "unavailable-bandwidth",
"metadata": {},
"source": [
"### 1.1.1.4 交互式环境"
@@ -143,7 +128,6 @@
},
{
"cell_type": "markdown",
- "id": "south-latex",
"metadata": {},
"source": [
"相比于其他编程语言,Python的一个特色是交互式环境,为我们提供了可以同时编写运行的编程方式。\n",
@@ -161,15 +145,13 @@
},
{
"cell_type": "markdown",
- "id": "appreciated-encounter",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "logical-japanese",
"metadata": {},
"source": [
"编写代码之后即刻运行,运行之后还可以继续编辑,省去了不停打开编写保存运行的过程,这便是交互式编程的奇妙之处!而交互式编程带来的便捷不止如此,在数据科学中我们经常要处理较大的数据,整个程序的运行动辄十几分钟。通过交互式编程我们可以一行一行运行程序,同时通过下面的输出内容观察程序的中间运行结果,在出现错误时及时修改代码,从而节省重复运行程序的时间!\n",
@@ -179,7 +161,6 @@
},
{
"cell_type": "markdown",
- "id": "worse-census",
"metadata": {},
"source": [
"## 1.1.2 Python 常量与变量"
@@ -187,7 +168,6 @@
},
{
"cell_type": "markdown",
- "id": "healthy-leave",
"metadata": {},
"source": [
"可能你现在会产生疑惑,代码中的 print 代表什么意义?括号又是什么作用?为什么 hello world 外面有个双引号?没关系,下面我们就来了解 Python 语法的奥秘。\n",
@@ -197,7 +177,6 @@
},
{
"cell_type": "markdown",
- "id": "independent-effects",
"metadata": {},
"source": [
"### 1.1.2.1 常量"
@@ -205,7 +184,6 @@
},
{
"cell_type": "markdown",
- "id": "soviet-architecture",
"metadata": {},
"source": [
"常量是编程语言中固定的量,它的值不能改变。例如 2 就表示数字二,不能被修改表示其他值。Python 中的常量包括数字,字符串,逻辑值三种。\n",
@@ -220,7 +198,6 @@
{
"cell_type": "code",
"execution_count": 6,
- "id": "extraordinary-projection",
"metadata": {},
"outputs": [
{
@@ -242,7 +219,6 @@
{
"cell_type": "code",
"execution_count": 7,
- "id": "treated-repeat",
"metadata": {},
"outputs": [
{
@@ -264,7 +240,6 @@
{
"cell_type": "code",
"execution_count": 8,
- "id": "acute-rescue",
"metadata": {},
"outputs": [
{
@@ -285,7 +260,6 @@
{
"cell_type": "code",
"execution_count": 10,
- "id": "turkish-clause",
"metadata": {},
"outputs": [
{
@@ -308,7 +282,6 @@
{
"cell_type": "code",
"execution_count": 24,
- "id": "reflected-optics",
"metadata": {},
"outputs": [
{
@@ -329,7 +302,6 @@
},
{
"cell_type": "markdown",
- "id": "medium-education",
"metadata": {},
"source": [
"### 1.1.2.2 变量"
@@ -337,7 +309,6 @@
},
{
"cell_type": "markdown",
- "id": "focal-assembly",
"metadata": {},
"source": [
"与常量相反,变量可以存储不同的值以表示不同的内容,并且它的值可以被更改。变量通过赋值符号 = 创建,例如variable = 1。\n",
@@ -348,7 +319,6 @@
{
"cell_type": "code",
"execution_count": 14,
- "id": "final-detection",
"metadata": {},
"outputs": [
{
@@ -372,7 +342,6 @@
{
"cell_type": "code",
"execution_count": 15,
- "id": "valuable-database",
"metadata": {},
"outputs": [
{
@@ -396,7 +365,6 @@
{
"cell_type": "code",
"execution_count": 19,
- "id": "handy-connection",
"metadata": {},
"outputs": [
{
@@ -417,7 +385,6 @@
{
"cell_type": "code",
"execution_count": 20,
- "id": "transsexual-theta",
"metadata": {},
"outputs": [
{
@@ -437,7 +404,6 @@
},
{
"cell_type": "markdown",
- "id": "elder-family",
"metadata": {},
"source": [
"## 1.1.3 Python 运算符与函数"
@@ -445,7 +411,6 @@
},
{
"cell_type": "markdown",
- "id": "sized-morocco",
"metadata": {},
"source": [
"学习了常量与变量之后,我们可以在Python中表示一些数值或字符串,然而要想解决更复杂的问题,我们需要了解如何对这些常量与变量进行操作。\n",
@@ -455,7 +420,6 @@
},
{
"cell_type": "markdown",
- "id": "parliamentary-vietnamese",
"metadata": {},
"source": [
"### 1.1.3.1 运算符"
@@ -463,7 +427,6 @@
},
{
"cell_type": "markdown",
- "id": "flexible-recipient",
"metadata": {},
"source": [
"运算符有以下几种,表示运算操作/逻辑操作/位运算操作\n",
@@ -504,7 +467,6 @@
},
{
"cell_type": "markdown",
- "id": "prime-horror",
"metadata": {},
"source": [
"> 问题:给你任意五个整数和一个目标值target,找到这五个整数中和为target的那两个整数。\n",
@@ -519,7 +481,6 @@
{
"cell_type": "code",
"execution_count": 36,
- "id": "electronic-james",
"metadata": {},
"outputs": [
{
@@ -545,7 +506,6 @@
{
"cell_type": "code",
"execution_count": 37,
- "id": "twenty-compression",
"metadata": {},
"outputs": [
{
@@ -568,7 +528,6 @@
{
"cell_type": "code",
"execution_count": 38,
- "id": "institutional-airplane",
"metadata": {},
"outputs": [
{
@@ -591,7 +550,6 @@
{
"cell_type": "code",
"execution_count": 39,
- "id": "atlantic-ghost",
"metadata": {},
"outputs": [
{
@@ -611,7 +569,6 @@
},
{
"cell_type": "markdown",
- "id": "dirty-trash",
"metadata": {},
"source": [
"### 1.1.3.2 函数"
@@ -619,7 +576,6 @@
},
{
"cell_type": "markdown",
- "id": "failing-fitness",
"metadata": {},
"source": [
"在上述过程中,下列代码被重复多次书写,这时我们可以使用函数减少代码冗余。函数是一种可复用的部件,用于定义更加复杂的操作以减少代码冗余。\n",
@@ -633,7 +589,6 @@
},
{
"cell_type": "markdown",
- "id": "dried-preliminary",
"metadata": {},
"source": [
"函数通过 def 关键字定义,函数的输入由函数名后括号内 参数 定义,函数的结果由 return 关键字定义。\n",
@@ -647,7 +602,6 @@
{
"cell_type": "code",
"execution_count": 62,
- "id": "athletic-mobility",
"metadata": {},
"outputs": [
{
@@ -671,7 +625,6 @@
{
"cell_type": "code",
"execution_count": 63,
- "id": "affiliated-tackle",
"metadata": {},
"outputs": [
{
@@ -694,7 +647,6 @@
},
{
"cell_type": "markdown",
- "id": "front-theorem",
"metadata": {},
"source": [
"下面我们尝试定义一个函数减少之前代码的冗余。"
@@ -703,7 +655,6 @@
{
"cell_type": "code",
"execution_count": 65,
- "id": "intellectual-beaver",
"metadata": {},
"outputs": [],
"source": [
@@ -719,7 +670,6 @@
},
{
"cell_type": "markdown",
- "id": "south-means",
"metadata": {},
"source": [
"Python的一大语法特点是缩进敏感,这里第 5,6,7 行距离开头有 1个TAB / 4个空格 的距离并不只是为了美观,而是为了说明第 5,6,7 行是函数的内容。相比下面 C++ 函数用花括号的表示方法,相信你可以在这个角度感受 Python 的简洁。 \n",
@@ -737,7 +687,6 @@
{
"cell_type": "code",
"execution_count": 66,
- "id": "intermediate-developer",
"metadata": {},
"outputs": [
{
@@ -762,7 +711,6 @@
},
{
"cell_type": "markdown",
- "id": "earlier-thirty",
"metadata": {},
"source": [
"通过引入函数,上面的小例子变得更加简洁。然而我们发现无论测试哪两个数字的和与target一致,target的值是始终不变的。我们可以通过引入 局部变量 与 全局变量 简化函数。\n",
@@ -778,7 +726,6 @@
{
"cell_type": "code",
"execution_count": 67,
- "id": "afraid-oasis",
"metadata": {},
"outputs": [
{
@@ -802,7 +749,6 @@
{
"cell_type": "code",
"execution_count": 68,
- "id": "prostate-dressing",
"metadata": {},
"outputs": [],
"source": [
@@ -818,7 +764,6 @@
{
"cell_type": "code",
"execution_count": 71,
- "id": "imperial-heaven",
"metadata": {},
"outputs": [
{
@@ -841,7 +786,6 @@
},
{
"cell_type": "markdown",
- "id": "conscious-slave",
"metadata": {},
"source": [
"通过 全局变量 的方法,我们的函数变得更加简洁了。"
@@ -849,7 +793,6 @@
},
{
"cell_type": "markdown",
- "id": "opening-story",
"metadata": {},
"source": [
"## 1.1.4 Python 控制流"
@@ -857,7 +800,6 @@
},
{
"cell_type": "markdown",
- "id": "humanitarian-deployment",
"metadata": {},
"source": [
"通过控制符与函数,我们可以操作变量完成简单的任务。然而本质上我们还在把 Python 当作一个计算器使用,而不是一个可以实现自动化的编程语言,每行代码按照自上而下的顺序依次执行。通过控制流,我们可以让程序自动判断逻辑,自动跳转到某个位置,从而实现自动控制。\n",
@@ -875,7 +817,6 @@
},
{
"cell_type": "markdown",
- "id": "third-background",
"metadata": {},
"source": [
"### 1.1.4.1 while 循环语句\n",
@@ -891,7 +832,6 @@
{
"cell_type": "code",
"execution_count": 76,
- "id": "unusual-preference",
"metadata": {},
"outputs": [
{
@@ -917,7 +857,6 @@
},
{
"cell_type": "markdown",
- "id": "capital-beach",
"metadata": {},
"source": [
"在上面的代码中,首先我们定义变量 a 的值为 0,之后每次迭代使 a 的值增加 1,并输出当前 a 的值。\n",
@@ -927,7 +866,6 @@
},
{
"cell_type": "markdown",
- "id": "revolutionary-execution",
"metadata": {},
"source": [
"### 1.1.4.2 for 循环语句\n",
@@ -949,7 +887,6 @@
{
"cell_type": "code",
"execution_count": 77,
- "id": "intellectual-prisoner",
"metadata": {},
"outputs": [
{
@@ -973,7 +910,6 @@
},
{
"cell_type": "markdown",
- "id": "funny-boost",
"metadata": {},
"source": [
"考虑之前的求和问题,在最坏的情况下,我们需要把所有元素两两求和才能得到答案。在5个元素时,我们最多需要对比10次,也就是重复写10次 check_sum 函数。但在有100个元素时,我们需要重复写4950次!因此这时我们用循环进行简化:"
@@ -982,7 +918,6 @@
{
"cell_type": "code",
"execution_count": 81,
- "id": "romance-deployment",
"metadata": {},
"outputs": [
{
@@ -1028,7 +963,6 @@
},
{
"cell_type": "markdown",
- "id": "nasty-district",
"metadata": {},
"source": [
"在这个例子中,我们可以看到循环是可以嵌套的,在循环的每一次迭代中开启一个新的循环。外层的 for a in [2,3,7,11,15] 按照顺序选择第 1 个元素,内层的 for b in [2,3,7,11,15] 按照顺序选择第 2 个元素,每次迭代输出两个值以及是否与 target 相等。\n",
@@ -1038,7 +972,6 @@
},
{
"cell_type": "markdown",
- "id": "fluid-shelf",
"metadata": {},
"source": [
"### 1.1.4.3 if-else 逻辑语句\n",
@@ -1055,7 +988,6 @@
},
{
"cell_type": "markdown",
- "id": "favorite-exploration",
"metadata": {},
"source": [
"虽然通过 for-in 不需要写很长代码,然而我们还需要从输出结果中一个个找。通过 if-else 逻辑语句,我们可以让程序真正的实现自动化!\n",
@@ -1066,7 +998,6 @@
{
"cell_type": "code",
"execution_count": 85,
- "id": "fixed-holder",
"metadata": {},
"outputs": [
{
@@ -1092,7 +1023,6 @@
},
{
"cell_type": "markdown",
- "id": "variable-butterfly",
"metadata": {},
"source": [
"通过 if-else 逻辑语句,我们仅输出求和等于 target 的两个元素,不再需要从输出结果中逐个查找。"
@@ -1100,7 +1030,6 @@
},
{
"cell_type": "markdown",
- "id": "cooked-shuttle",
"metadata": {},
"source": [
"### 1.1.4.4 break 停止语句"
@@ -1108,7 +1037,6 @@
},
{
"cell_type": "markdown",
- "id": "bizarre-prerequisite",
"metadata": {},
"source": [
"break 停止语句用于停止当前的循环。在上面的例子中,我们仅输出 1 种顺序即可,可以添加 break 停止语句在找到符合条件的两个元素后停止。\n",
@@ -1119,7 +1047,6 @@
{
"cell_type": "code",
"execution_count": 87,
- "id": "worthy-salmon",
"metadata": {},
"outputs": [
{
@@ -1151,7 +1078,6 @@
},
{
"cell_type": "markdown",
- "id": "objective-blackjack",
"metadata": {},
"source": [
"### 1.1.4.5 continue 继续语句"
@@ -1159,7 +1085,6 @@
},
{
"cell_type": "markdown",
- "id": "acoustic-closer",
"metadata": {},
"source": [
"continue 语句用于停止当前循环并继续执行循环到下一个迭代,下面我们用一个例子展示 continue 的用法。"
@@ -1168,7 +1093,6 @@
{
"cell_type": "code",
"execution_count": 89,
- "id": "hearing-history",
"metadata": {},
"outputs": [
{
@@ -1193,7 +1117,6 @@
},
{
"cell_type": "markdown",
- "id": "built-enclosure",
"metadata": {},
"source": [
"## 1.1.5 练习"
@@ -1201,7 +1124,6 @@
},
{
"cell_type": "markdown",
- "id": "anticipated-rogers",
"metadata": {},
"source": [
"### 1.1.5.1 练习一"
@@ -1209,7 +1131,6 @@
},
{
"cell_type": "markdown",
- "id": "former-peeing",
"metadata": {},
"source": [
"> 按规定,某种电子元件使用寿命超过 1000 小时为一级品。已知某一大批产品的一级品率为 0.2,现在从中随机地抽查 20 只。使用 Python 计算 20 只元件中恰好有 k 只 (k=0,1,...,20) 为一级品的概率为?"
@@ -1217,7 +1138,6 @@
},
{
"cell_type": "markdown",
- "id": "superb-antarctica",
"metadata": {},
"source": [
"根据二项分布公式,所求的概率为:\n",
@@ -1231,7 +1151,6 @@
{
"cell_type": "code",
"execution_count": 108,
- "id": "clinical-square",
"metadata": {},
"outputs": [],
"source": [
@@ -1247,7 +1166,6 @@
{
"cell_type": "code",
"execution_count": 110,
- "id": "vulnerable-publicity",
"metadata": {},
"outputs": [],
"source": [
@@ -1264,7 +1182,6 @@
{
"cell_type": "code",
"execution_count": 117,
- "id": "certain-gentleman",
"metadata": {},
"outputs": [
{
@@ -1305,22 +1222,16 @@
}
],
"metadata": {
+ "interpreter": {
+ "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
+ },
"kernelspec": {
- "display_name": "Python 3",
- "language": "python",
+ "display_name": "Python 3.9.2 64-bit",
"name": "python3"
},
"language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
"name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.9.2"
+ "version": ""
},
"toc": {
"base_numbering": 1,
@@ -1338,4 +1249,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
-}
+}
\ No newline at end of file
diff --git a/4. Python 文件与模块.ipynb b/4. Python 文件与模块.ipynb
index 9c14d64..110d2e9 100644
--- a/4. Python 文件与模块.ipynb
+++ b/4. Python 文件与模块.ipynb
@@ -2,7 +2,6 @@
"cells": [
{
"cell_type": "markdown",
- "id": "0e7782b2",
"metadata": {},
"source": [
"# Python 文件与模块"
@@ -10,7 +9,6 @@
},
{
"cell_type": "markdown",
- "id": "e76c313b",
"metadata": {},
"source": [
"## 1.4.1 文件"
@@ -18,7 +16,6 @@
},
{
"cell_type": "markdown",
- "id": "0b7db359",
"metadata": {},
"source": [
"经过几百万年的演化,人类进化出了其他动物没有的“长期记忆”,进而拥有了语言、文化甚至发展出文明,走上了一条未曾设想的道路。在人类大脑中,“短期记忆”由海马体负责,“长期记忆”则由大脑皮层中的额叶负责;在计算机中也同样存在长短期记忆,短期记忆由程序中的变量负责,长期记忆则交给电脑中的文件系统。"
@@ -26,7 +23,6 @@
},
{
"cell_type": "markdown",
- "id": "1d652ca4",
"metadata": {},
"source": [
"### 1.4.1.1 Open 函数"
@@ -34,7 +30,6 @@
},
{
"cell_type": "markdown",
- "id": "3cc3d3af",
"metadata": {},
"source": [
"Python open( ) 方法用于打开一个文件,并返回文件对象,在对文件进行处理过程都需要使用到这个函数。"
@@ -42,17 +37,15 @@
},
{
"cell_type": "markdown",
- "id": "9d0e9846",
"metadata": {},
"source": [
"> 为了测试 python 中的文件操作,我们先通过命令行在当前目录保存一个内容为 “hello world!” 的 test.txt 文件。\n",
"\n",
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "1509a325",
"metadata": {},
"source": [
"open(file, mode) 函数主要有 file 和 mode 两个参数,其中 file 为需要读写文件的路径。mode 为读取文件时的模式,常用的模式有以下几个:\n",
@@ -68,7 +61,6 @@
{
"cell_type": "code",
"execution_count": 1,
- "id": "661dc70a",
"metadata": {},
"outputs": [
{
@@ -86,7 +78,6 @@
},
{
"cell_type": "markdown",
- "id": "32cf4402",
"metadata": {},
"source": [
"### 1.4.1.2 文件对象"
@@ -94,7 +85,6 @@
},
{
"cell_type": "markdown",
- "id": "a8b4deb3",
"metadata": {},
"source": [
"open 函数会返回一个 文件对象。在进行文件操作前,我们首先需要了解文件对象提供了哪些常用的方法:\n",
@@ -111,7 +101,6 @@
},
{
"cell_type": "markdown",
- "id": "7420694e",
"metadata": {},
"source": [
"下面我们通过实例学习这几种方法:"
@@ -120,7 +109,6 @@
{
"cell_type": "code",
"execution_count": 2,
- "id": "6de241f1",
"metadata": {},
"outputs": [
{
@@ -142,7 +130,6 @@
{
"cell_type": "code",
"execution_count": 3,
- "id": "a972b570",
"metadata": {},
"outputs": [
{
@@ -161,7 +148,6 @@
},
{
"cell_type": "markdown",
- "id": "34a5ace0",
"metadata": {},
"source": [
"我们发现上面的代码竟然什么也没输出,这是为什么?\n",
@@ -172,7 +158,6 @@
{
"cell_type": "code",
"execution_count": 4,
- "id": "cf96733e",
"metadata": {},
"outputs": [
{
@@ -195,7 +180,6 @@
},
{
"cell_type": "markdown",
- "id": "7d50ca1b",
"metadata": {},
"source": [
"因此在操作文件时,我们一定要注意每次操作结束后,及时通过 close( ) 方法关闭文件。"
@@ -204,7 +188,6 @@
{
"cell_type": "code",
"execution_count": 5,
- "id": "d7851cf0",
"metadata": {},
"outputs": [],
"source": [
@@ -220,15 +203,13 @@
},
{
"cell_type": "markdown",
- "id": "f111f706",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "b101985e",
"metadata": {},
"source": [
"需要注意在上述操作中,w 模式会覆盖之前的文件。如果你想在文件后面追加内容,可以使用 a 模式操作。"
@@ -237,7 +218,6 @@
{
"cell_type": "code",
"execution_count": 6,
- "id": "59b7a526",
"metadata": {},
"outputs": [],
"source": [
@@ -253,15 +233,13 @@
},
{
"cell_type": "markdown",
- "id": "9f972ac7",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "03ece181",
"metadata": {},
"source": [
"## 1.4.2 模块"
@@ -269,7 +247,6 @@
},
{
"cell_type": "markdown",
- "id": "cfe62671",
"metadata": {},
"source": [
"在普罗米修斯为人类带来火种后,人类制造出了各种各样的工具。工具的产生大大提高了人类的生产力,使人类从石器时代步入铁器时代、蒸汽时代以及现在的信息时代。\n",
@@ -279,7 +256,6 @@
},
{
"cell_type": "markdown",
- "id": "f1a6d448",
"metadata": {},
"source": [
"编写模块的方式有很多,其中最简单的模块就是创建一个包含很多函数、变量以及类并以 .py 为后缀的文件。下面我们把上一节中实现的 class 类保存在 student.py 文件中:"
@@ -287,15 +263,13 @@
},
{
"cell_type": "markdown",
- "id": "5e8f9a48",
"metadata": {},
"source": [
- "
"
+ "
"
]
},
{
"cell_type": "markdown",
- "id": "ea559988",
"metadata": {},
"source": [
"使用 import 关键字可以把一个模块引入到一个程序来使用它的功能。记得在上一节中我们说过一个程序也可以是一个对象,这时 student.py 程序就成了一个对象,而里面的 student 类便成了它的对象变量。"
@@ -304,7 +278,6 @@
{
"cell_type": "code",
"execution_count": 7,
- "id": "96ccfcc6",
"metadata": {},
"outputs": [],
"source": [
@@ -314,7 +287,6 @@
{
"cell_type": "code",
"execution_count": 8,
- "id": "09379a79",
"metadata": {},
"outputs": [
{
@@ -332,7 +304,6 @@
},
{
"cell_type": "markdown",
- "id": "4ead1338",
"metadata": {},
"source": [
"通过 student.py 这个模块,我们不需要重复编写就可以在任何程序中使用 student 类!正是因为有了模块,才使得数据科学中复杂的算法与模型可以封装到模块中,用户只需要使用模块中定义好的函数与类。"
@@ -340,7 +311,6 @@
},
{
"cell_type": "markdown",
- "id": "265da85c",
"metadata": {},
"source": [
"当我们只需要模块中的几个函数或类时,也可以采用 from model_name import xxx 的写法导入指定部分:"
@@ -349,7 +319,6 @@
{
"cell_type": "code",
"execution_count": 9,
- "id": "2c30c2b8",
"metadata": {},
"outputs": [
{
@@ -370,7 +339,6 @@
},
{
"cell_type": "markdown",
- "id": "27c50efb",
"metadata": {},
"source": [
"在 Python 中内置了很多标准模块,例如用于数学操作的 math 模块与处理时间的 time 模块:"
@@ -379,7 +347,6 @@
{
"cell_type": "code",
"execution_count": 10,
- "id": "f11f5959",
"metadata": {},
"outputs": [
{
@@ -399,7 +366,6 @@
{
"cell_type": "code",
"execution_count": 11,
- "id": "ee6f806f",
"metadata": {},
"outputs": [
{
@@ -421,7 +387,6 @@
},
{
"cell_type": "markdown",
- "id": "49799951",
"metadata": {},
"source": [
"除此之外,Python 还有很多标准库值得我们去探索。例如 re 库可以实现字符串正则表达式的匹配,random 用来生成随机数,urllib 用来访问互联网……"
@@ -429,7 +394,6 @@
},
{
"cell_type": "markdown",
- "id": "23ac88a6",
"metadata": {},
"source": [
"## 1.4.3 练习"
@@ -437,7 +401,6 @@
},
{
"cell_type": "markdown",
- "id": "5b052280",
"metadata": {},
"source": [
"### 1.4.3.1 学生信息本地存储"
@@ -445,7 +408,6 @@
},
{
"cell_type": "markdown",
- "id": "db815ccf",
"metadata": {},
"source": [
"> 之前我们实现了学生信息的“增删查改”功能,现在希望通过文件系统保存学生的信息,每次打开程序时可以载入,关闭程序时可以保存。"
@@ -453,7 +415,6 @@
},
{
"cell_type": "markdown",
- "id": "53166325",
"metadata": {},
"source": [
"### 1.4.3.2 Python 之蝉"
@@ -461,7 +422,6 @@
},
{
"cell_type": "markdown",
- "id": "dc7e6e64",
"metadata": {},
"source": [
"
\n", @@ -478,7 +438,6 @@ { "cell_type": "code", "execution_count": 12, - "id": "9b0d40db", "metadata": { "scrolled": false }, @@ -517,22 +476,16 @@ } ], "metadata": { + "interpreter": { + "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" + }, "kernelspec": { - "display_name": "Python 3", - "language": "python", + "display_name": "Python 3.9.2 64-bit", "name": "python3" }, "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "" }, "toc": { "base_numbering": 1, @@ -550,4 +503,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} +} \ No newline at end of file diff --git a/README.md b/README.md index 54de5e8..e83d5dd 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# learn-python-the-smart-way -聪明方法学Python,简明且系统的 Python 入门教程。 +# 聪明办法学Python + diff --git a/src/fig11.png b/src/fig11.png new file mode 100644 index 0000000..9e0cece Binary files /dev/null and b/src/fig11.png differ diff --git a/src/fig12.png b/src/fig12.png new file mode 100644 index 0000000..2a3858f Binary files /dev/null and b/src/fig12.png differ diff --git a/src/fig13.png b/src/fig13.png new file mode 100644 index 0000000..55ab208 Binary files /dev/null and b/src/fig13.png differ diff --git a/src/fig14.png b/src/fig14.png new file mode 100644 index 0000000..e08efae Binary files /dev/null and b/src/fig14.png differ diff --git a/src/fig41.png b/src/fig41.png new file mode 100644 index 0000000..d4788d7 Binary files /dev/null and b/src/fig41.png differ diff --git a/src/fig42.png b/src/fig42.png new file mode 100644 index 0000000..0901357 Binary files /dev/null and b/src/fig42.png differ diff --git a/src/fig43.png b/src/fig43.png new file mode 100644 index 0000000..289c5be Binary files /dev/null and b/src/fig43.png differ diff --git a/src/fig44.png b/src/fig44.png new file mode 100644 index 0000000..0bb333f Binary files /dev/null and b/src/fig44.png differ