# 继承
# class A:pass # 父类,基类,超类
# class A1:pass
# class A_son(A):pass # 子类,派生类
# class A1_son(A,A1):pass # Python特性,支持多继承
# print(A.__bases__) # 所有类默认继承object类(新式类),Python3中所有的类都有父类
# print(A_son.__bases__) # 查看一个类继承了那些父类
# print(A1_son.__bases__) # (<class '__main__.A'>, <class '__main__.A1'>) 顺序即为继承的顺序
# # 例:(子类可以继承父类的方法,子类也可以有自己独有的方法--派生方法)
# class Animal:
# def __init__(self,name,color):
# self.name = name
# self.color = color
# def play(self):
# print("{} 在玩耍".format(self.name))
#
# class Cat(Animal):
# def eat(self):
# print('一只%s的猫,名叫%s,在吃鱼'%(self.color,self.name))
#
# class Mouse(Animal):
# def bark(self):
# print('一只%s的老鼠,名叫%s,在吱吱叫'%(self.color,self.name))
#
# tom = Cat('汤姆','灰色')
# jerry = Mouse('杰瑞','棕色')
# tom.eat()
# jerry.bark()
# tom.play()
# jerry.play()
# 子类与父类有同名方法默认使用子类的
# class A: # Python3中所有的类默认继承objec类,是新式类
# def __init__(self,args1,args2):
# self.args1 = args1
# self.args2 = args2
# def show(self):
# print("A has two args:args1-->{},args2-->[]".format(self.args1,self.args2))
# class B(A):
# def __init__(self,args1,args2,args3):
# self.args1 = args1
# self.args2 = args2
# self.args3 = args3
# def show(self):
# print("B has three args:args1-->{},args2-->{},args3-->{}".format(self.args1,self.args2,self.args3))
#
# b = B('b1','b2','b3')
# b.show() # B has three args:args1-->b1,args2-->b2,args3-->b3
# 如果还想调用父类的方法一
# class A: # Python3中所有的类默认继承objec类,是新式类
# def __init__(self,args1,args2):
# self.args1 = args1
# self.args2 = args2
# def show(self):
# print("A has two args:args1-->{},args2-->{}".format(self.args1,self.args2))
# class B(A):
# def __init__(self,args1,args2,args3):
# super().__init__(args1,args2)
# self.args3 = args3
# def show(self):
# super().show()
# print("B has three args:args1-->{},args2-->{},args3-->{}".format(self.args1,self.args2,self.args3))
#
# b = B('a1','a2','b3')
# b.show()
# # A has two args:args1-->a1,args2-->a2
# # B has three args:args1-->a1,args2-->a2,args3-->b3
# super(B,b).show() # super还可以在外部调用
# 如果还想调用父类的方法二(Python2中只支持这种)
# class A: # Python3中所有的类默认继承objec类,是新式类
# def __init__(self,args1,args2):
# self.args1 = args1
# self.args2 = args2
# def show(self):
# print("A has two args:args1-->{},args2-->{}".format(self.args1,self.args2))
# class B(A):
# def __init__(self,args1,args2,args3):
# A.__init__(self,args1,args2)
# self.args3 = args3
# def show(self):
# A.show(self)
# print("B has three args:args1-->{},args2-->{},args3-->{}".format(self.args1,self.args2,self.args3))
#
# b = B('a1','a2','b3')
# b.show()
# A has two args:args1-->a1,args2-->a2
# B has three args:args1-->a1,args2-->a2,args3-->b3
# Python种的多继承
# class A:
# pass
# # def show(self):print('A')
#
# class B:
# pass
# def show(self):print('B')
# class C:
# pass
# # def show(self):print('C')
#
# class D(A,B,C):
# pass
# # def show(self):print('D')
#
# d = D()
# d.show() # 自己有的方法执行自己的 ---D
# d.show() # 注释def show(self):print('D') --- A
# d.show() # 注释def show(self):print('A') ---B
# d.show() # 注释def show(self):print('B') ---C
# d.show() # 注释def show(self):print('C') ---报错
# 钻石继承
# class A:
# # pass
# def show(self):print('A')
#
# class B(A):
# pass
# # def show(self):print('B')
#
# class C(A):
# pass
# # def show(self):print('C')
#
# class D(B,C):
# pass
# # def show(self):print('D')
#
# d = D()
# d.show() # 自己有的方法执行自己的 ---D
# d.show() # 注释def show(self):print('D') ---B
# d.show() # 注释def show(self):print('B') ---C
# d.show() # 注释def show(self):print('C') ---A
# 继承顺序进阶
# class A:
# # pass
# def show(self):print('A')
#
# class B(A):
# pass
# # def show(self):print('B')
#
# class C(A):
# pass
# # def show(self):print('C')
#
# class E(B):
# pass
# # def show(self):print('E')
#
# class F(C):
# pass
# # def show(self):print('F')
#
# class D(E,F):
# pass
# # def show(self):print('D')
# d = D()
# d.show() # 自己有的方法执行自己的 ---D
# d.show() # 注释def show(self):print('D') ---E
# d.show() # 注释def show(self):print('E') ---B
# d.show() # 注释def show(self):print('B') ---F
# d.show() # 注释def show(self):print('F') ---C
# d.show() # 注释def show(self):print('C') ---A
# print(D.mro()) # 新式类查看继承顺序的方法
# 新式类中遵循广度优先原则,但是要以保证每一个类都有被找到的前提下,经典类中遵循深度优先
# super的真正作用
# class A:
# # pass
# def show(self):print('A')
#
# class B(A):
# def show(self):
# super().show()
# print('B')
#
# class C(A):
# def show(self):
# super().show()
# print('C')
#
# class E(B):
# def show(self):
# super().show()
# print('E')
#
# class F(C):
# def show(self):
# super().show()
# print('F')
#
# class D(E,F):
# def show(self):
# super().show()
# print('D')
#
# d = D()
# d.show()
# 输出结果 -- super并非直接找父类方法,而是根据调用者在继承顺序中的位置按继承顺序调用方法
# A
# C
# F
# B
# E
# D