How to call a Parent Class's method from Child Class in Python?

后端 未结 15 2633
無奈伤痛
無奈伤痛 2020-11-22 10:14

When creating a simple object hierarchy in Python, I\'d like to be able to invoke methods of the parent class from a derived class. In Perl and Java, there is a keyword for

15条回答
  •  一向
    一向 (楼主)
    2020-11-22 11:00

    class department:
        campus_name="attock"
        def printer(self):
            print(self.campus_name)
    
    class CS_dept(department):
        def overr_CS(self):
            department.printer(self)
            print("i am child class1")
    
    c=CS_dept()
    c.overr_CS()
    

提交回复
热议问题