<p>这两个属性是<em>类属性</em>或<a href="https://stackoverflow.com/questions/68645/static-class-variables-in-python"><em>static variables</em></a>。如果要声明非静态属性,则必须在变量名称前面加上<code>self</code>,这表示您正在使用的类的当前实例:</p>
<pre><code>class MyClass:
def __init__(self):
self.suitList = ["CLubs"]
self.number = 1
</code></pre>
<p>有关什么是<code>self</code>以及静态类变量和非静态类变量之间的差异的更多信息:</p>
<ol>
<li><p><a href="https://stackoverflow.com/questions/625083/python-init-and-self-what-do-they-do">Python __init__ and self what do they do?</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/6019627/python-self-keyword">Python 'self' keyword</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/6990099/explaining-the-python-self-variable-to-a-beginner">Explaining the python 'self' variable to a beginner</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/2709821/python-self-explained?rq=1">What is the purpose of self?</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/3332454/oop-python-oriented-tutorials">https://stackoverflow.com/questions/3332454/oop-python-oriented-tutorials</a></p></li>
<li><p><a href="https://stackoverflow.com/questions/207000/python-difference-between-class-and-instance-attributes">Python: Difference between class and instance attributes</a></p></li>
</ol>