class P(object): 'P class' def __init__(self): print('created an instance of',self.__class__.__name__) def foo(self): print('Hi,I am P-foo()')class C(P): def foo(self): P.foo(self) #子类的重写方法显式地调用基类方法 super(C,self).foo() #P.foo(self)等价super(C,self).foo()等价super().foo() super().foo() print('Hi,I am C-foo()')p=P()c=C()# print(p.__class__) # p所属的类名# print(P.__bases__) # 父类的父类# print(P.__doc__) # 父类的文档字符串# print('-'*50)# print(c.__class__) # c所属的类名# print(C.__bases__) # 子类的父类print('-'*50)# p.foo() #实例调用方法# c.foo() #子类调用基类的覆盖方法# P.foo(c) #调用未绑定的基类方法,把子类实例传参进去c.foo()
来源:https://www.cnblogs.com/jinpingzhao/p/12630336.html