Skip to content

Commit 74a576f

Browse files
committed
p3
1 parent 51ee68a commit 74a576f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

209.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125

126126
在子类`Girl`中,只写了一个方法`get_name()`,但是因为是继承了`Person`,那么`Girl`就全部拥有了`Person`中的方法和属性。子类`Girl`的方法`get_name()`中,使用了属性`self.name`,但是在类`Girl`中,并没有什么地方显示创建了这个属性,就是因为继承`Person`类,在父类中有初始化函数。所以,当使用子类创建实例的时候,必须传一个参数`cang = Girl("canglaoshi")`,然后调用实例方法`cang.get_name()`。对于实例方法`cang.height(160)`,也是因着继承的缘故使然。
127127

128-
在上面的程序中,子类`Gril`里面没有与父类`Person`重复的属性和方法,但有时候,会遇到这样的情况。
128+
在上面的程序中,子类`Girl`里面没有与父类`Person`重复的属性和方法,但有时候,会遇到这样的情况。
129129

130130
class Girl(Person):
131131
def __init__(self):
@@ -207,7 +207,7 @@ Python 3中也有异常:
207207
def get_name(self):
208208
return self.name
209209

210-
仅仅修改一处,将`Person.__init__(self, name)`去掉,修改为`super(Girl, self).__init__(name)`实行程序后,显示的结果与以前一样。
210+
仅仅修改一处,将`Person.__init__(self, name)`修改为`super(Girl, self).__init__(name)`执行程序后,显示的结果与以前一样。
211211

212212
关于`super`,有人做了非常深入的研究,推荐读者阅读[《Python’s super() considered super! 》](https://rhettinger.wordpress.com/2011/05/26/super-considered-super/),文中已经探究了`super`的工作过程。读者如果要深入了解,可以阅读这篇文章。
213213

0 commit comments

Comments
 (0)