擅长:python、mysql、java
<p>在这一点上,没有自我:</p>
<pre><code>class test:
self.x = None
# ^^^^^ BAD
</code></pre>
<p>在初始值设定项中将其更改为:</p>
<pre><code>class test:
def __init__(self):
self.x = None
</code></pre>
<p>或者通常使用class属性。你知道吗</p>
<pre><code>class test:
x = None
</code></pre>
<p>如果你不确定是哪一种,那就用第一种;在你对差异更有信心之前,使用这种模式会让你不那么困惑。你知道吗</p>