问答详情
源自:3-4 Python中的多态

多重继承init的参数问题

class SkillMixin():
    def __init__(self, skill):
        self.__skill = skill
    
    def get_skill(self):
        return self.__skill
        
class BasketballMixin(SkillMixin):
    def __init__(self):
        super(BasketballMixin, self).__init__('basketball') #这里会报参数错误 why?

class FootballMixin(SkillMixin):
    def __init__(self):
        super(FootballMixin, self).__init__('football')
        
class BasketballAndFootball (BasketballMixin, FootballMixin):
    def __init__(self):
        super(BasketballAndFootball, self).__init__()
   
s1 = BasketballMixin()      
s2 = BasketballAndFootball()

注释的地方会报错 提示只有1个参数但是给了两个


不符合原题目,但是不懂这里为啥会报错

提问者:慕的地4684329 2022-02-06 21:20

个回答

  • weixin_慕用0068683
    2022-02-13 12:07:36

    在子类init方法里,比如第9行应该是 def __init__(self,skill):