python继承
python继承
class parent(object):
def __init__(self):
super(parent, self).__init__()
self.func = None
def func_hand(self):
self.func()
def printf():
print('hello python!')
class child(parent):
def __init__(self):
super(child, self).__init__()
self.func = printf
def test(self):
self.func_hand()
instance = child()
instance.test()
父类中self.func并没有定义,在子类中定义,然后子类调用父类的self.func_hand->self.func。
每天快乐敲代码,快乐生活

浙公网安备 33010602011771号