# ### 菱形继承 ''' Human Man Woman Children ''' class Human(): pty = 111 def feelT(self): print("远古人类天热了,脱毛1") print(self.pty) print("远古人类天冷了,长毛2") class Man(Human): pty = 222 def feelT(self): print("现代男性天热了,开空调3") super().feelT() print("现代男性天冷了,也开空调4") class Woman(Human): pty = 333 def feelT(self): print("现代女性天热了,穿比基尼5") super().feelT() print("现代女性天冷了,也穿比基尼,要风度,不要温度6") class Children(Man,Woman): pty = 444 def feelT(self): print("小孩天热了,他就吃冰棍哭7") super().feelT() print("小孩天冷了,他就吃奶奶哭8") obj = Children() obj.feelT() # 731211 # 73511112 ''' # mro列表 :通过c3算法,把所有的继承关系按照列表的顺序呈现. # 语法: 类.mro() => 继承顺序列表 [ <class '__main__.Children'>, <class '__main__.Man'>, <class '__main__.Woman'>, <class '__main__.Human'>, <class 'object'> ] super 就是默认按照mro列表的顺序,依次调用 用于解决多继承调用顺序混乱的问题 ''' lst = Children.mro() print(lst) # 判断是否是子父关系 [有血缘关系即可] issubclass res = issubclass(Children,Man) res = issubclass(Children,Human) # 满足一个条件,即返回真 res = issubclass(Children,(Man,Woman)) print(res) # 判断对象的类型 [有血缘关系即可] isinstance res = isinstance(obj,Children) res = isinstance(obj,Man) res = isinstance(obj,(Human,Woman)) print(res)