{"id":1123527,"date":"2025-01-08T19:33:09","date_gmt":"2025-01-08T11:33:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1123527.html"},"modified":"2025-01-08T19:33:12","modified_gmt":"2025-01-08T11:33:12","slug":"python%e4%b8%ad%e5%ad%90%e7%b1%bb%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8%e7%88%b6%e7%b1%bb%e7%9a%84%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1123527.html","title":{"rendered":"python\u4e2d\u5b50\u7c7b\u5982\u4f55\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084941\/7bdd0194-cd6e-4f99-998e-0fa5df84baf4.webp\" alt=\"python\u4e2d\u5b50\u7c7b\u5982\u4f55\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5b50\u7c7b\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\uff1a\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u3001\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\u3001\u4f7f\u7528\u7c7b\u540d\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\u3002<\/strong> \u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u662f\u6700\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u8fd8\u80fd\u5904\u7406\u591a\u91cd\u7ee7\u627f\u7684\u95ee\u9898\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u5c55\u5f00\u5176\u4e2d\u7684\u4e00\u70b9\uff1a\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u53ef\u4ee5\u5728\u5b50\u7c7b\u4e2d\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\uff0c\u800c\u65e0\u9700\u660e\u786e\u6307\u5b9a\u7236\u7c7b\u7684\u540d\u79f0\u3002\u8fd9\u4f7f\u5f97\u4ee3\u7801\u66f4\u5177\u7075\u6d3b\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u591a\u91cd\u7ee7\u627f\u65f6\u3002\u901a\u8fc7 <code>super()<\/code> \u51fd\u6570\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u786e\u4fdd\u5b50\u7c7b\u7ee7\u627f\u7684\u6240\u6709\u7236\u7c7b\u65b9\u6cd5\u90fd\u80fd\u6b63\u786e\u6267\u884c\uff0c\u4ece\u800c\u907f\u514d\u6f5c\u5728\u7684\u9519\u8bef\u548c\u51b2\u7a81\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4ec0\u4e48\u662f\u7ee7\u627f\u548c\u65b9\u6cd5\u91cd\u8f7d\uff1f<\/h3>\n<\/p>\n<p><h4>1\u3001\u7ee7\u627f\u7684\u57fa\u672c\u6982\u5ff5<\/h4>\n<\/p>\n<p><p>\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08OOP\uff09\u7684\u4e00\u4e2a\u57fa\u672c\u6982\u5ff5\uff0c\u901a\u8fc7\u7ee7\u627f\uff0c\u4e00\u4e2a\u7c7b\uff08\u5b50\u7c7b\uff09\u53ef\u4ee5\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\uff08\u7236\u7c7b\uff09\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u5728Python\u4e2d\uff0c\u7ee7\u627f\u901a\u8fc7\u7c7b\u5b9a\u4e49\u65f6\u7684\u62ec\u53f7\u6765\u8868\u793a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Parent:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(f&quot;Hello, my name is {self.name}.&quot;)<\/p>\n<p>class Child(Parent):<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        super().__init__(name)<\/p>\n<p>        self.age = age<\/p>\n<p>    def greet(self):<\/p>\n<p>        super().greet()<\/p>\n<p>        print(f&quot;I am {self.age} years old.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c<code>Child<\/code> \u7c7b\u7ee7\u627f\u4e86 <code>Parent<\/code> \u7c7b\uff0c\u5e76\u91cd\u8f7d\u4e86 <code>greet<\/code> \u65b9\u6cd5\u3002\u5728 <code>Child<\/code> \u7c7b\u7684 <code>greet<\/code> \u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7 <code>super().greet()<\/code> \u8c03\u7528\u4e86\u7236\u7c7b\u7684 <code>greet<\/code> \u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u65b9\u6cd5\u91cd\u8f7d\u7684\u542b\u4e49<\/h4>\n<\/p>\n<p><p>\u65b9\u6cd5\u91cd\u8f7d\u662f\u6307\u5728\u5b50\u7c7b\u4e2d\u5b9a\u4e49\u4e0e\u7236\u7c7b\u540c\u540d\u7684\u65b9\u6cd5\uff0c\u4ece\u800c\u8986\u76d6\u7236\u7c7b\u7684\u65b9\u6cd5\u3002\u65b9\u6cd5\u91cd\u8f7d\u5141\u8bb8\u5b50\u7c7b\u63d0\u4f9b\u81ea\u5df1\u7684\u5b9e\u73b0\uff0c\u540c\u65f6\u4ecd\u7136\u80fd\u591f\u8c03\u7528\u7236\u7c7b\u7684\u5b9e\u73b0\u3002\u65b9\u6cd5\u91cd\u8f7d\u5728\u591a\u6001\u6027\u7684\u5b9e\u73b0\u4e2d\u8d77\u5230\u4e86\u5173\u952e\u4f5c\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5982\u4f55\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570<\/h3>\n<\/p>\n<p><h4>1\u3001\u57fa\u672c\u7528\u6cd5<\/h4>\n<\/p>\n<p><p><code>super()<\/code> \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u7236\u7c7b\u7684\u5bf9\u8c61\uff0c\u901a\u8fc7\u8fd9\u4e2a\u5bf9\u8c61\uff0c\u53ef\u4ee5\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u3002\u5b83\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u4e0d\u9700\u8981\u5bfc\u5165\u4efb\u4f55\u6a21\u5757\u5373\u53ef\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Parent:<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(&quot;Hello from Parent&quot;)<\/p>\n<p>class Child(Parent):<\/p>\n<p>    def greet(self):<\/p>\n<p>        super().greet()<\/p>\n<p>        print(&quot;Hello from Child&quot;)<\/p>\n<p>child = Child()<\/p>\n<p>child.greet()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c<code>super().greet()<\/code> \u8c03\u7528\u4e86\u7236\u7c7b\u7684 <code>greet<\/code> \u65b9\u6cd5\uff0c\u7136\u540e\u6267\u884c\u5b50\u7c7b\u7684 <code>greet<\/code> \u65b9\u6cd5\u8f93\u51fa\u3002\u7ed3\u679c\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code>Hello from Parent<\/p>\n<p>Hello from Child<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u591a\u91cd\u7ee7\u627f<\/h4>\n<\/p>\n<p><p>\u591a\u91cd\u7ee7\u627f\u662f\u6307\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u7ee7\u627f\u591a\u4e2a\u7236\u7c7b\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c<code>super()<\/code> \u51fd\u6570\u4f1a\u6309\u7167\u65b9\u6cd5\u89e3\u6790\u987a\u5e8f\uff08Method Resolution Order, MRO\uff09\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u3002MRO \u662f\u4e00\u4e2a\u7c7b\u5c42\u6b21\u7ed3\u6784\u4e2d\uff0c\u5404\u7c7b\u7684\u641c\u7d22\u987a\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class A:<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;A&quot;)<\/p>\n<p>class B(A):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;B&quot;)<\/p>\n<p>        super().say()<\/p>\n<p>class C(A):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;C&quot;)<\/p>\n<p>        super().say()<\/p>\n<p>class D(B, C):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;D&quot;)<\/p>\n<p>        super().say()<\/p>\n<p>d = D()<\/p>\n<p>d.say()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7c7b <code>D<\/code> \u7ee7\u627f\u4e86\u7c7b <code>B<\/code> \u548c <code>C<\/code>\uff0c\u800c <code>B<\/code> \u548c <code>C<\/code> \u53c8\u5206\u522b\u7ee7\u627f\u4e86\u7c7b <code>A<\/code>\u3002\u8c03\u7528 <code>d.say()<\/code> \u5c06\u4f1a\u6309\u7167MRO\u987a\u5e8f\u8c03\u7528\u5404\u7c7b\u7684 <code>say<\/code> \u65b9\u6cd5\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code>D<\/p>\n<p>B<\/p>\n<p>C<\/p>\n<p>A<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570<\/h3>\n<\/p>\n<p><h4>1\u3001\u901a\u8fc7\u7c7b\u540d\u8c03\u7528<\/h4>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u8c03\u7528\u7236\u7c7b\u65b9\u6cd5\u7684\u65b9\u6cd5\u662f\u76f4\u63a5\u4f7f\u7528\u7236\u7c7b\u7684\u7c7b\u540d\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u662f\u6709\u7528\u7684\uff0c\u7279\u522b\u662f\u5728\u9700\u8981\u660e\u786e\u6307\u660e\u8c03\u7528\u7684\u7236\u7c7b\u65f6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Parent:<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(&quot;Hello from Parent&quot;)<\/p>\n<p>class Child(Parent):<\/p>\n<p>    def greet(self):<\/p>\n<p>        Parent.greet(self)<\/p>\n<p>        print(&quot;Hello from Child&quot;)<\/p>\n<p>child = Child()<\/p>\n<p>child.greet()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7 <code>Parent.greet(self)<\/code> \u76f4\u63a5\u8c03\u7528\u4e86\u7236\u7c7b\u7684 <code>greet<\/code> \u65b9\u6cd5\uff0c\u8f93\u51fa\u7ed3\u679c\u4e0e\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u76f8\u540c\u3002<\/p>\n<\/p>\n<p><pre><code>Hello from Parent<\/p>\n<p>Hello from Child<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u9002\u7528\u573a\u666f<\/h4>\n<\/p>\n<p><p>\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u5728\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\u662f\u6709\u7528\u7684\uff0c\u4f8b\u5982\uff0c\u5f53\u5b50\u7c7b\u9700\u8981\u8c03\u7528\u7279\u5b9a\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u6309\u7167MRO\u987a\u5e8f\u8fdb\u884c\u8c03\u7528\u65f6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class A:<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;A&quot;)<\/p>\n<p>class B(A):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;B&quot;)<\/p>\n<p>        A.say(self)<\/p>\n<p>class C(A):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;C&quot;)<\/p>\n<p>        A.say(self)<\/p>\n<p>class D(B, C):<\/p>\n<p>    def say(self):<\/p>\n<p>        print(&quot;D&quot;)<\/p>\n<p>        B.say(self)<\/p>\n<p>d = D()<\/p>\n<p>d.say()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>D.say()<\/code> \u4e2d\u660e\u786e\u8c03\u7528\u4e86 <code>B.say(self)<\/code>\uff0c\u7136\u540e <code>B<\/code> \u7c7b\u518d\u8c03\u7528 <code>A<\/code> \u7c7b\u7684\u65b9\u6cd5\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<\/p>\n<p><pre><code>D<\/p>\n<p>B<\/p>\n<p>A<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5b50\u7c7b\u8c03\u7528\u7236\u7c7b\u6784\u9020\u51fd\u6570<\/h3>\n<\/p>\n<p><h4>1\u3001\u901a\u8fc7 <code>super()<\/code> \u8c03\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u5b50\u7c7b\u7684\u6784\u9020\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>super()<\/code> \u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\uff0c\u4ece\u800c\u786e\u4fdd\u7236\u7c7b\u7684\u521d\u59cb\u5316\u4ee3\u7801\u88ab\u6267\u884c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Parent:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(f&quot;Hello, my name is {self.name}.&quot;)<\/p>\n<p>class Child(Parent):<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        super().__init__(name)<\/p>\n<p>        self.age = age<\/p>\n<p>    def greet(self):<\/p>\n<p>        super().greet()<\/p>\n<p>        print(f&quot;I am {self.age} years old.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u901a\u8fc7 <code>super().__init__(name)<\/code> \u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\uff0c\u4ece\u800c\u521d\u59cb\u5316\u4e86 <code>name<\/code> \u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u901a\u8fc7\u7c7b\u540d\u8c03\u7528<\/h4>\n<\/p>\n<p><p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u7236\u7c7b\u7684\u7c7b\u540d\u76f4\u63a5\u8c03\u7528\u6784\u9020\u51fd\u6570\uff0c\u8fd9\u5728\u67d0\u4e9b\u590d\u6742\u7684\u7ee7\u627f\u5173\u7cfb\u4e2d\u53ef\u80fd\u66f4\u4e3a\u76f4\u89c2\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Parent:<\/p>\n<p>    def __init__(self, name):<\/p>\n<p>        self.name = name<\/p>\n<p>    def greet(self):<\/p>\n<p>        print(f&quot;Hello, my name is {self.name}.&quot;)<\/p>\n<p>class Child(Parent):<\/p>\n<p>    def __init__(self, name, age):<\/p>\n<p>        Parent.__init__(self, name)<\/p>\n<p>        self.age = age<\/p>\n<p>    def greet(self):<\/p>\n<p>        Parent.greet(self)<\/p>\n<p>        print(f&quot;I am {self.age} years old.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u9762\u7684\u4ee3\u7801\u901a\u8fc7 <code>Parent.__init__(self, name)<\/code> \u76f4\u63a5\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6784\u9020\u51fd\u6570\uff0c\u6548\u679c\u4e0e\u4f7f\u7528 <code>super()<\/code> \u51fd\u6570\u76f8\u540c\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h3>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528 <code>super()<\/code> \u7684\u4f18\u70b9<\/h4>\n<\/p>\n<ul>\n<li><strong>\u7b80\u6d01\u660e\u4e86<\/strong>\uff1a\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u4e0d\u9700\u8981\u663e\u5f0f\u5730\u6307\u5b9a\u7236\u7c7b\u7684\u540d\u79f0\u3002<\/li>\n<li><strong>\u9002\u5e94\u591a\u91cd\u7ee7\u627f<\/strong>\uff1a\u81ea\u52a8\u5904\u7406\u591a\u91cd\u7ee7\u627f\u7684MRO\u95ee\u9898\uff0c\u786e\u4fdd\u65b9\u6cd5\u8c03\u7528\u987a\u5e8f\u6b63\u786e\u3002<\/li>\n<li><strong>\u53ef\u7ef4\u62a4\u6027\u9ad8<\/strong>\uff1a\u7236\u7c7b\u540d\u79f0\u53d8\u66f4\u65f6\uff0c\u5b50\u7c7b\u4ee3\u7801\u65e0\u9700\u4fee\u6539\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002<\/li>\n<\/ul>\n<p><h4>2\u3001\u4f55\u65f6\u4f7f\u7528\u76f4\u63a5\u8c03\u7528<\/h4>\n<\/p>\n<ul>\n<li><strong>\u660e\u786e\u8c03\u7528\u7279\u5b9a\u7236\u7c7b\u65b9\u6cd5<\/strong>\uff1a\u5728\u9700\u8981\u660e\u786e\u8c03\u7528\u67d0\u4e2a\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u6309\u7167MRO\u987a\u5e8f\u65f6\uff0c\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u66f4\u4e3a\u5408\u9002\u3002<\/li>\n<li><strong>\u590d\u6742\u7ee7\u627f\u5173\u7cfb<\/strong>\uff1a\u5728\u590d\u6742\u7684\u7ee7\u627f\u5173\u7cfb\u4e2d\uff0c\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u76f4\u89c2\u6027\u3002<\/li>\n<\/ul>\n<p><p>\u5728Python\u4e2d\uff0c\u5b50\u7c7b\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u9700\u6c42\u3002\u901a\u8fc7\u4e86\u89e3\u548c\u638c\u63e1 <code>super()<\/code> \u51fd\u6570\u548c\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u65b9\u6cd5\u7684\u6280\u5de7\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5b9e\u73b0\u4ee3\u7801\u7684\u91cd\u7528\u548c\u7ee7\u627f\uff0c\u4ece\u800c\u63d0\u9ad8\u4ee3\u7801\u7684\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u786e\u8ba4\u5b50\u7c7b\u662f\u5426\u6210\u529f\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u5b50\u7c7b\u4e2d\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\u6765\u786e\u8ba4\u8c03\u7528\u662f\u5426\u6210\u529f\u3002\u53ef\u4ee5\u5728\u91cd\u5199\u7684\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u6253\u5370\u8bed\u53e5\uff0c\u6216\u8005\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u67e5\u770b\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u6e05\u695a\u5730\u770b\u5230\u7236\u7c7b\u7684\u51fd\u6570\u662f\u5426\u88ab\u8c03\u7528\u3002<\/p>\n<p><strong>\u5728\u4f7f\u7528\u591a\u91cd\u7ee7\u627f\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u5b50\u7c7b\u6b63\u786e\u8c03\u7528\u7236\u7c7b\u7684\u65b9\u6cd5\uff1f<\/strong><br \/>\u591a\u91cd\u7ee7\u627f\u65f6\uff0c\u4f7f\u7528<code>super()<\/code>\u51fd\u6570\u53ef\u4ee5\u786e\u4fdd\u8c03\u7528\u5230\u6b63\u786e\u7684\u7236\u7c7b\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cPython\u4f1a\u6309\u7167\u65b9\u6cd5\u89e3\u6790\u987a\u5e8f\uff08MRO\uff09\u6765\u67e5\u627e\u65b9\u6cd5\uff0c\u786e\u4fdd\u60a8\u8c03\u7528\u7684\u662f\u6b63\u786e\u7684\u7236\u7c7b\u3002\u8fd9\u79cd\u65b9\u6cd5\u6709\u52a9\u4e8e\u907f\u514d\u6f5c\u5728\u7684\u51b2\u7a81\u548c\u4e0d\u786e\u5b9a\u6027\u3002<\/p>\n<p><strong>\u5982\u679c\u5b50\u7c7b\u91cd\u5199\u4e86\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u5982\u4f55\u5728\u5b50\u7c7b\u4e2d\u4ecd\u7136\u8bbf\u95ee\u7236\u7c7b\u7684\u5b9e\u73b0\uff1f<\/strong><br \/>\u5728\u5b50\u7c7b\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>super().method_name()<\/code>\u7684\u65b9\u5f0f\u6765\u8bbf\u95ee\u7236\u7c7b\u7684\u5b9e\u73b0\u3002\u8fd9\u79cd\u65b9\u5f0f\u5141\u8bb8\u60a8\u5728\u6267\u884c\u5b50\u7c7b\u7279\u5b9a\u7684\u903b\u8f91\u4e4b\u540e\uff0c\u4ecd\u7136\u80fd\u591f\u8c03\u7528\u5e76\u6267\u884c\u7236\u7c7b\u7684\u529f\u80fd\uff0c\u4ece\u800c\u4fdd\u7559\u4e86\u7236\u7c7b\u65b9\u6cd5\u7684\u6240\u6709\u7279\u6027\u4e0e\u884c\u4e3a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5b50\u7c7b\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\uff1a\u4f7f\u7528 super() \u51fd\u6570\u3001\u76f4\u63a5\u8c03\u7528\u7236\u7c7b\u7684\u51fd\u6570\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1123534,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123527"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1123527"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123527\/revisions"}],"predecessor-version":[{"id":1123536,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123527\/revisions\/1123536"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1123534"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1123527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1123527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1123527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}