python调用父类函数(python调用父类的三种方法)
导读:面向对象的继承中,我们会涉及到父类的调用。在对继承的基础内容有所了解后,我们进一步探究调用父类的三种方法。...
面向对象的继承中 ,我们会涉及到父类的调用 。在对继承的基础内容有所了解后 ,我们进一步探究调用父类的三种方法 。
1 、父类名字.父类方法名(self,[参数1 ,参数2 ,参数3,……]) 。
2 、super().父类方法名([参数1 ,参数2 ,参数3,……]) 。
3 、super(当前类名字,self).父类方法名([参数1 ,参数2……]) 。
实例
classPerson(object): def__init__(self,name,gender): self.name=name self.gender=gender print("Person类__init__() 。","姓名:",self.name) classStudent(Person): def__init__(self,name,gender,score): super().__init__(name,gender) self.score=score print("Student类__init__() 。","姓名:",self.name) student=Student(tom,male,10)以上就是python调用父类的三种方法 ,希望对大家有所帮助 。更多Python学习指路:Python基础教程
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!