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

后端 未结 15 2587
無奈伤痛
無奈伤痛 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 a(object):
        def my_hello(self):
            print "hello ravi"
    
    class b(a):
        def my_hello(self):
        super(b,self).my_hello()
        print "hi"
    
    obj = b()
    obj.my_hello()
    

提交回复
热议问题