Skip to content

Commit d4ed9c7

Browse files
committed
修改了部分文档
1 parent d2b3141 commit d4ed9c7

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,4 @@
1414
151.101.184.133 camo.githubusercontent.com
1515
```
1616

17-
<center>图1. 公开课信息</center>
18-
19-
![](res/open-course.png)
20-
21-
<center>图2. 扫码加入公开课</center>
22-
23-
![](res/qrcode.png)
24-
25-
<center>图3. 学习交流群信息</center>
26-
2717
![](res/qrcode-group.png)

第016课:面向对象编程入门.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ print(students) # [骆昊: 40, 王小锤: 16, 王大锤: 25]
131131
```
132132

133133

134-
135-
136134
### 面向对象的支柱
137135

138136
面向对象编程有三大支柱,就是我们之前给大家划重点的时候圈出的三个词:封装、继承和多态。后面两个概念在下一节课中会详细说明,这里我们先说一下什么是封装。我自己对封装的理解是:**隐藏一切可以隐藏的实现细节,只向外界暴露简单的调用接口**。我们在类中定义的对象方法其实就是一种封装,这种封装可以让我们在创建对象之后,只需要给对象发送一个消息就可以执行方法中的代码,也就是说我们在只知道方法的名字和参数(方法的外部视图),不知道方法内部实现细节(方法的内部视图)的情况下就完成了对方法的使用。

第020课:函数使用进阶.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ print(calc(1, 2, c=3, d=4)) # 10
7979
如果我们希望上面的`calc`函数不仅仅可以做多个参数求和,还可以做多个参数求乘积甚至更多的二元运算,我们就可以使用高阶函数的方式来改写上面的代码,将加法运算从函数中移除掉,具体的做法如下所示。
8080

8181
```Python
82-
def calc(*, init_value, op, *args, **kwargs):
82+
def calc(*args, init_value, op, **kwargs):
8383
result = init_value
8484
for arg in args:
8585
result = op(result, arg)
@@ -99,8 +99,8 @@ def mul(x, y):
9999
return x * y
100100

101101

102-
print(calc(init_value=0, op=add, 1, 2, 3, x=4, y=5)) # 15
103-
print(calc(init_value=1, op=mul, 1, 2, x=3, y=4, z=5)) # 120
102+
print(calc(1, 2, 3, init_value=0, op=add, x=4, y=5)) # 15
103+
print(calc(1, 2, x=3, y=4, z=5, init_value=1, op=mul)) # 120
104104
```
105105

106106
通过对高阶函数的运用,`calc`函数不再和加法运算耦合,所以灵活性和通用性会变强,这是编程中一种常用的技巧,但是最初学者来说可能会稍微有点难以理解。需要注意的是,将函数作为参数和调用函数是有显著的区别的,**调用函数需要在函数名后面跟上圆括号,而把函数作为参数时只需要函数名即可**。上面的代码也可以不用定义`add``mul`函数,因为Python标准库中的`operator`模块提供了代表加法运算的`add`和代表乘法运算的`mul`函数,我们直接使用即可,代码如下所示。

0 commit comments

Comments
 (0)