Python 为一切类都提供了一个 bases 属性,经过该属性能够查看该类的一切间接父类,该属性前往一切间接父类组成的元组。留意是间接父类!!!

应用语法:类名.bases
举例阐明 (保举学习:Python视频教程)
举例:界说三个类Vehicle(车)、Automobile(汽车)、Car(小汽车),为了阐明成绩,将Car设置为承继自Vehicle以及Automobile两个类,而Automobile承继Vehicle。类界说以下:
class Vehicle():
def __init__(self,wheelcount):
self.wheelcount = wheelcount
class Automobile(Vehicle):
def __init__(self,wheelcount,power):
self.power,self.totaldistance = '燃油发起机',0
super().__init__(wheelcount)
class Car(Automobile,Vehicle):
def __init__(self,wheelcount, power,oilcostperkm):
self.oilcostperkm = oilcostperkm
super().__init__(wheelcount, power)咱们来查看这三个类的__bases__,患上出论断以下:
Car.的间接父类是Automobile、Vehicle;
Automobile的间接父类是Vehicle;
Automobile的间接父类是object。
详细执行截屏以下:


以上就是python若何查看父类的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!