标签:div pass 执行 def sel 子类 object span super
示例
class Base(object): def func(self): print(‘Base.func‘) class Foo(Base): def func(self): # 方式一:根据mro的顺序执行方法 # super(Foo,self).func() # 方式二:主动执行Base类的方法 Base.func(self) print(‘Foo.func‘) obj = Foo() obj.func() ‘‘‘ Base.func Foo.func ‘‘‘ #################################### ‘‘‘ class Base(object): def func(self): super(Base, self).func() print(‘Base.func‘) class Bar(object): def func(self): print(‘Bar.func‘) class Foo(Base,Bar): pass ‘‘‘ # 示例一 # obj = Foo() # obj.func() # ‘‘‘ # Bar.func # Base.func # ‘‘‘ # print(Foo.__mro__) #(<class ‘__main__.Foo‘>, <class ‘__main__.Base‘>, <class ‘__main__.Bar‘>, <class ‘object‘>) # 示例二 # obj = Base() # obj.func() #报错 Base父类Object中无func方法
标签:div pass 执行 def sel 子类 object span super
原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/13232983.html