Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
class subclass(superclass): def __init__(self, arg1, arg2): superclass.__init__(self, blah1, blah2)
使用的目的是superclass.__init__(self, blah1, blah2)什么?关于在继承超类时是否使用最后一行,我有点困惑。
superclass.__init__(self, blah1, blah2)
superclass.__init__(self,*args,**kwargs)
基本上相当于
super(Myclass,self).__init__(*args,**kwargs)
那就是它调用 supers 构造函数。但它跳过了继承堆栈的其余部分(我认为super()气泡或其他东西......大多数时候我使用第一种方法)
super()
**这可能过于简化