python调用父类的三种方法

1,908次阅读
没有评论

python调用父类的三种方法

面向对象的继承中,我们会涉及到父类的调用。在对继承的基础内容有所了解后,我们进一步探究调用父类的三种方法。

1、父类名字.父类方法名(self,[参数1,参数2,参数3,……])。

2、super().父类方法名([参数1,参数2,参数3,……])。

3、super(当前类名字,self).父类方法名([参数1,参数2……])。

实例

class Person(object):
    def __init__(self,name,gender):
        self.name =name
        self.gender =gender
        print("Person类__init__()。", "姓名:",self.name)
class Student(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调用父类的三种方法,希望对大家有所帮助。

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2022-06-16发表,共计564字。
新手QQ群:570568346,欢迎进群讨论 Python51学习