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