擅长:python、mysql、java
<p>@FogleBird已经回答了你的问题,但我想补充一些东西,不能评论他的帖子:</p>
<p>您可能还想看看<a href="http://docs.python.org/library/functions.html#super" rel="nofollow">^{<cd1>} function</a>。这是一种从子级内部调用父级方法的方法。当您想扩展方法时,它很有用,例如:</p>
<pre><code>class ParentClass(object):
def __init__(self, x):
self.x = x
class ChildClass(ParentClass):
def __init__(self, x, y):
self.y = y
super(ChildClass, self).__init__(x)
</code></pre>
<p>这当然可以包含更复杂的方法,<em>不是</em>方法<code>__init__</code>甚至是同名的方法!在</p>