擅长:python、mysql、java
<p>当<code>SubTest</code>的新实例被创建时,<code>TopTest.__init__()</code>被调用-因为<code>SubTest</code>继承了{<cd2>}-这将使<code>TopTest.count</code>增加两倍。在</p>
<p>而且由于<code>SubTest</code>从未定义类级别的<code>count</code>变量,所以当<code>SubTest.count</code>被执行时,Python会后退并使用<code>TopTest.count</code>。在</p>
<p>可以通过将<code>count</code>本地重新定义为<code>SubTest</code>来修复此行为。在</p>
<pre><code>class SubTest(TopTest):
count = 0
</code></pre>