首页 > 编程语言 > 详细

python3 多继承

时间:2021-07-19 22:57:15      阅读:24      评论:0      收藏:0      [点我收藏+]

 

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
class FooParent(object):
    def __init__(self):
        self.parent = ‘I\‘m the parent.‘
        print (‘Parent‘)
    
    def bar(self,message):
        print ("%s from Parent" % message)
 
class FooChild(FooParent):
    def __init__(self):
        # super(FooChild,self) 首先找到 FooChild 的父类(就是类 FooParent),然后把类 FooChild 的对象转换为类 FooParent 的对象
        #super(FooChild,self).__init__()    
        print (‘Child‘)
        
    def bar(self,message):
        super(FooChild, self).bar(message)
        print (‘Child bar fuction‘)
        print (self.parent)
 
if __name__ == ‘__main__‘:
    fooChild = FooChild()
    fooChild.bar(‘HelloWorld‘)
不会执行FooParent的init


python3 多继承搜索__init__方法的两种策略
https://www.cnblogs.com/wujiaqing/p/10861026.html

python3 多继承

原文:https://www.cnblogs.com/liuxingxing/p/15031878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!