立即学习:https://edu.csdn.net/course/play/24797/282192?utm_source=blogtoedu
class TestFu: def fuleifun(self): print('这是父类TestFu的【fuleifun】函数') def fuleifun2(self): print('这是父类TestFu的【fuleifun2】函数') class TestFu2: def fuleifun(self): self.x = print('这是父类TestFu2的【fuleifun】函数') def fuleifunOther(self): print('这是父类TestFu2的【funleifunOther】函数') # 继承父类函数 class TestZi(TestFu): pass zi = TestZi() zi.fuleifun() print('*' * 50) ''' 多继承 多继承,如果多父类中有相同的函数,优先使用继承靠前的类的函数 相同函数【fuleifun】,优先使用【TestFu2】中的【fuleifun】函数 ''' class TestZi2(TestFu2, TestFu): pass zi2 = TestZi2() # 调用类【TestFu2】中的函数 zi2.fuleifun() # 调用类【TestFu】中的函数 zi2.fuleifun2() zi2.fuleifunOther() print('*' * 50) ''' 重写父类【TestFu2】中的【fuleifunOther】函数 ''' class TestZi3(TestFu2): def fuleifunOther(self): print('这是子类【TestZi3】重写父类【TestFu2】中的【fuleifunOther】函数') zi3 = TestZi3() zi3.fuleifunOther()
1.多继承优先使用先继承父类中的函数