diff options
author | Hui Lan <lanhui@zjnu.edu.cn> | 2019-06-10 20:40:38 +0800 |
---|---|---|
committer | Hui Lan <lanhui@zjnu.edu.cn> | 2019-06-10 20:40:38 +0800 |
commit | 257844fcc016817334dc0375fbaa5b005e0836ba (patch) | |
tree | 00b9688b1189bef0c5c3a90bda0f56c1b9dd441c /LectureNotesOnPython.rst | |
parent | 3384c1cd75ac196c8c30ed08f4953198a96a6d05 (diff) |
LectureNotesOnPython.rst: 修改后面几个章节的层级结构。
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r-- | LectureNotesOnPython.rst | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst index 191c164..81277f2 100644 --- a/LectureNotesOnPython.rst +++ b/LectureNotesOnPython.rst @@ -17,7 +17,7 @@ Lecture Notes on Python 前言 -------------------------------------------------------------------- -非学究写书,无空洞行文。 +... 非学究写书,无空洞行文。 Python语法简洁,库函数全面强大,编程速度快,运行速度也不慢。 @@ -1518,7 +1518,7 @@ Memo 类 class 与 对象 object -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------------------------------------------------ 程序员用类(class)来定义一类数据。 @@ -1555,7 +1555,7 @@ blank 是(指向) Point类型的对象的一个变量。 注意到Point后 一个对象可以是另外一个对象的属性 -```````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python @@ -1590,7 +1590,8 @@ blank 是(指向) Point类型的对象的一个变量。 注意到Point后 copy 与 deepcopy -```````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + copy 拷贝类中的属性, 但不会重新制作一个对象中的对象 (embedded object),而是拷贝其引用而已。 而deepcopy会。 @@ -1643,7 +1644,8 @@ copy 拷贝类中的属性, 但不会重新制作一个对象中的对象 (e 纯函数与修改函数 -```````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 纯函数(pure function)。 @@ -1713,7 +1715,8 @@ copy 拷贝类中的属性, 但不会重新制作一个对象中的对象 (e 调用类方法 -```````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + .. code:: python @@ -1745,7 +1748,7 @@ copy 拷贝类中的属性, 但不会重新制作一个对象中的对象 (e 方法中可以定义函数 -`````````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python @@ -1811,7 +1814,8 @@ Positional argument. Keyword argument. 多态 (polymorphism) -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 如果函数可以对多个类型使用,我们把它叫做多态函数。 如histogram,可以对字符串使用去数里面字符的频率, 也可以对列表使用去数里面元素的频率。 @@ -1856,7 +1860,8 @@ Positional argument. Keyword argument. 继承(inheritance) -`````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 继承用于从父类(parent)中继承属性与方法,创建一个子类 (child)。 如果 子类中的方法与父类中的方法同名, 则在子类实例中用子类定义的方法 @@ -2107,13 +2112,14 @@ IS-A 。 一手牌是一副牌。 print(rq.format_results()) -web 应用程序 -```````````` +Web 应用程序 +--------------------------------------------------- 我们将使用 Flask 这个 Python 微型框架来实现网页应用程序。 在文本框输入文本 -`````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 利用 Flask 库中的 request 实现前端与后端的信息传递。 @@ -2261,17 +2267,17 @@ Firefox打开 127.0.0.1:5000 这个网址即可运行。 上传文件 -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ omg 其它有用的Python语言特性 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +---------------------------------------------------- 条件表达 -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 把 if else 写在一行。看函数 take_log3。 @@ -2313,7 +2319,8 @@ omg Generator表达 -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Generator也是一个对象,对象里面有 __iter__ 与 __next__ 方法。 当所有的元素都遍历完之后,抛出 **StopIteration** 异常。 @@ -2339,7 +2346,8 @@ Generator也是一个对象,对象里面有 __iter__ 与 __next__ 方法。 any 与 all -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + any/all 是个函数,可以接收 list 或 generator 类型的参数。 @@ -2360,7 +2368,7 @@ any/all 是个函数,可以接收 list 或 generator 类型的参数。 集合 Sets -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: python @@ -2391,7 +2399,8 @@ any/all 是个函数,可以接收 list 或 generator 类型的参数。 计数 Counter -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 与字典有点像。 @@ -2410,7 +2419,8 @@ any/all 是个函数,可以接收 list 或 generator 类型的参数。 defaultdict -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + 可以避免第一次加 value 时 key 不在引起的 KeyError。 @@ -2447,7 +2457,8 @@ defaultdict 收集keyword args -``````````````````````````````````````````````````` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + .. code:: python |