python中super () . __init__()怎么用

  介绍

这篇文章给大家分享的是有关python中超级(). __init__()怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

class 父亲:   ,,,def  __init__(自我,,father_attribute=癴ather"):   ,,,,,,,self.father_attribute=father_attribute      class  child_without_ini(父亲):   ,才能通过      class  child_with_ini(父亲):   ,,,def  __init__(自我,,child_attribute):   ,,,,,,,self.child_attribute=child_attribute      class  child_with_super(父亲):   ,,,def  __init__(自我、father_attribute super_attribute):   ,,,,,,,self.super_attribute=super_attribute   ,,,,,,,超级(). __init__ (father_attribute)      test_class_without_ini=child_without_ini ()   test_class_with_ini=child_with_ini(& # 39;孩子# 39;)   test_class_with_super=child_with_super (& # 39; new_father& # 39; & # 39;超级# 39;)         测试:      打印(test_class_without_ini.father_attribute)   输出:   父亲      打印(test_class_with_ini.father_attribute)   输出:   AttributeError: & # 39; child_with_ini& # 39;, object  has  no  attribute  & # 39; father_attribute& # 39;      打印(test_class_with_super.father_attribute)   输出:   new_father

class  child_with_super(父亲):   ,,,def  __init__(自我、father_attribute super_attribute):   ,,,,,,,超级(child_with_super,,自我). __init__ (father_attribute)   ,,,,,,,自我。super_attribute=super_attribute

感谢各位的阅读!关于python中超级(). __init__()怎么用就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

python中super () . __init__()怎么用