【问题标题】:class M and Class F are two classes .why "super()" method of F is calling the init method of M? Surely class M is not a parent of class FM类和F类是两个类。为什么F的“super()”方法调用了M的init方法?当然 M 类不是 F 类的父级
【发布时间】:2022-06-13 21:43:38
【问题描述】:

类 M 和 F 是两个独立的类。 C 类继承了 F 和 M 。我不明白为什么类 F 的 super() 关键字调用类 M 的 init 。有人可以解释这段代码背后的工作原理吗?

 class M:
       def __init__(self):
         print("M constructor")


class F:
       def __init__(self):
          print("F constructor")
          super().__init__()
          super().__init__()

class C(F,M):
     def __init__(self):
        super().__init__()
        print("C constructor")

C()

O/P

F 构造函数

M 构造函数

M 构造函数

C 构造函数

【问题讨论】:

标签: python python-3.x oop


猜你喜欢
  • 2015-03-06
  • 2012-02-20
  • 1970-01-01
  • 1970-01-01
  • 2019-10-11
  • 2021-10-30
  • 2010-11-02
  • 1970-01-01
  • 2016-01-24
相关资源
最近更新 更多