Python __init__ syntax

后端 未结 2 1081
囚心锁ツ
囚心锁ツ 2021-02-14 13:42

While learning Python I\'m having some confusion over the syntax of the initialization of classes using inheritance. In various examples I\'ve seen something like the following

2条回答
  •  日久生厌
    2021-02-14 14:02

    Generally passing parent is not something that's required, only when the parent class's constructor explicitly needs such an argument. This is used in some hierarchies, such as PyQt.

    And a good idiom of parent class initialization is to use super:

    class Child(Father):
      def __init__(self):
        super(Child, self).__init__()
    

提交回复
热议问题