各位读者,小编来为大家解答,learn python the hard way (笨办法学python) 笨办法学python 3电子书下载,现在让我们一起来看看吧!
编程中的继承和多态其实跟生物学中的遗传非常类似PHP,我学习路上的那盏灯。例如儿子与父亲相比较,有很多相同的地方,那么这就是遗传;但是父子间也有很多不一样的地方,那么这就是变异,也就是多态。
python中的Student
类继承了People
类中的所有方法和属性,那么就有了People
所有的属性和方法。当然Student
也可以在People
的基础上添加属性和方法,也可以修改继承自People
的属性和方法(覆写,Overide)。
例如:
class People(object):
name = "people"
age = ""
def walk(self):
print + "Walk"
class Student(People):
name = "Student"
def walk(self):
super(Student, self).walk()
print "hshhs"
def run(self):
print "run"
student = Student()
()
输出:
StudentWalk
hshhs
原文地址1:https://blog.csdn.net/weixin_34358365/article/details/89136571
参考资料:python中用turtle画一个圆形 https://blog.csdn.net/SXIAOYAN_/article/details/140061099