• <tfoot id='sHmvk'></tfoot>

    <i id='sHmvk'><tr id='sHmvk'><dt id='sHmvk'><q id='sHmvk'><span id='sHmvk'><b id='sHmvk'><form id='sHmvk'><ins id='sHmvk'></ins><ul id='sHmvk'></ul><sub id='sHmvk'></sub></form><legend id='sHmvk'></legend><bdo id='sHmvk'><pre id='sHmvk'><center id='sHmvk'></center></pre></bdo></b><th id='sHmvk'></th></span></q></dt></tr></i><div id='sHmvk'><tfoot id='sHmvk'></tfoot><dl id='sHmvk'><fieldset id='sHmvk'></fieldset></dl></div>

    <small id='sHmvk'></small><noframes id='sHmvk'>

      • <bdo id='sHmvk'></bdo><ul id='sHmvk'></ul>

        <legend id='sHmvk'><style id='sHmvk'><dir id='sHmvk'><q id='sHmvk'></q></dir></style></legend>
      1. “超级"在 Python 中做了什么?- super().__init__() 和显式超类 __init__(

        What does #39;super#39; do in Python? - difference between super().__init__() and explicit superclass __init__()(“超级在 Python 中做了什么?- super().__init__() 和显式超类 __init__() 之间的区别)
        <legend id='5maUu'><style id='5maUu'><dir id='5maUu'><q id='5maUu'></q></dir></style></legend>

        <small id='5maUu'></small><noframes id='5maUu'>

            <tbody id='5maUu'></tbody>
              <bdo id='5maUu'></bdo><ul id='5maUu'></ul>

              <tfoot id='5maUu'></tfoot>
              <i id='5maUu'><tr id='5maUu'><dt id='5maUu'><q id='5maUu'><span id='5maUu'><b id='5maUu'><form id='5maUu'><ins id='5maUu'></ins><ul id='5maUu'></ul><sub id='5maUu'></sub></form><legend id='5maUu'></legend><bdo id='5maUu'><pre id='5maUu'><center id='5maUu'></center></pre></bdo></b><th id='5maUu'></th></span></q></dt></tr></i><div id='5maUu'><tfoot id='5maUu'></tfoot><dl id='5maUu'><fieldset id='5maUu'></fieldset></dl></div>

                • 本文介绍了“超级"在 Python 中做了什么?- super().__init__() 和显式超类 __init__() 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  两者有什么区别:

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

                  和:

                  class Child(SomeBaseClass):
                      def __init__(self):
                          SomeBaseClass.__init__(self)
                  

                  我已经看到 super 在只有单一继承的类中被大量使用.我可以理解您为什么要在多重继承中使用它,但不清楚在这种情况下使用它有什么优势.

                  I've seen super being used quite a lot in classes with only single inheritance. I can see why you'd use it in multiple inheritance but am unclear as to what the advantages are of using it in this kind of situation.

                  推荐答案

                  super() 在单继承中的好处是微乎其微的——大多数情况下,您不必对将基类的名称添加到使用其父方法的每个方法中.

                  The benefits of super() in single-inheritance are minimal -- mostly, you don't have to hard-code the name of the base class into every method that uses its parent methods.

                  但是,如果没有 super(),几乎不可能使用多重继承.这包括常见的习惯用法,如 mixins、接口、抽象类等.这会扩展到以后扩展您的代码.如果后来有人想编写一个扩展 Child 和 mixin 的类,他们的代码将无法正常工作.

                  However, it's almost impossible to use multiple-inheritance without super(). This includes common idioms like mixins, interfaces, abstract classes, etc. This extends to code that later extends yours. If somebody later wanted to write a class that extended Child and a mixin, their code would not work properly.

                  这篇关于“超级"在 Python 中做了什么?- super().__init__() 和显式超类 __init__() 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                        <tbody id='AX6F5'></tbody>

                        <i id='AX6F5'><tr id='AX6F5'><dt id='AX6F5'><q id='AX6F5'><span id='AX6F5'><b id='AX6F5'><form id='AX6F5'><ins id='AX6F5'></ins><ul id='AX6F5'></ul><sub id='AX6F5'></sub></form><legend id='AX6F5'></legend><bdo id='AX6F5'><pre id='AX6F5'><center id='AX6F5'></center></pre></bdo></b><th id='AX6F5'></th></span></q></dt></tr></i><div id='AX6F5'><tfoot id='AX6F5'></tfoot><dl id='AX6F5'><fieldset id='AX6F5'></fieldset></dl></div>
                          <bdo id='AX6F5'></bdo><ul id='AX6F5'></ul>

                          <small id='AX6F5'></small><noframes id='AX6F5'>

                          <legend id='AX6F5'><style id='AX6F5'><dir id='AX6F5'><q id='AX6F5'></q></dir></style></legend>
                          <tfoot id='AX6F5'></tfoot>