37. Python------ init和继承
python修炼第十五天
2019年 3月31日 晴
class Dog:
def __init__(self):
self.type = "狗"
class XTQ(Dog):
def __init__(self): # 一旦重写init方法, 父类中定义的属性将不会继承
# 这种情况下, 想要继承父类的属性, 必须手动调用父类的init方法
Dog.__init__(self)
# super(XTQ,self).__init__()
# super().__init__()
self.color = "黑"
# pass
xtq = XTQ()
print(xtq.color)
print(xtq.type)
执行结果
D:\studing学习\python_63_init和继承.py
黑
狗
Process finished with exit code 0