2018-12-11派森学习第23天

笨方法学python中强调:

Most of the uses of inheritance can be simplified or replaced with composition, and multiple inheri- tance should be avoided at all costs.

继承的大部分用途可以简化或者用组合替换,并且应该不惜一切代价避免多次继承。

类的第一种用法:

implicit inheritance

2018-12-11派森学习第23天_第1张图片
隐形继承


第二种:

override

2018-12-11派森学习第23天_第2张图片
重写

第三种:

Alter Before or After

就是可以选择到底用子类重写的函数,还是使用基类的函数。

2018-12-11派森学习第23天_第3张图片
出现错误

出现错误,不知道哪里错了。

把输入参数修改到实例化对象后,正确运行了:

2018-12-11派森学习第23天_第4张图片
正确

super()函数可以把子类从重写的函数中拯救出来,使用原来的父类的函数。

你可能感兴趣的:(2018-12-11派森学习第23天)