擅长:python、mysql、java
<p>名为<code>variable</code>的变量是局部变量。具体来说,它是<code>__init__()</code>方法的局部。您将无法在该方法之外访问它。您只能在方法内部访问它。在<code>__init__()</code>方法中创建的局部变量实际上只用于创建其他实例变量:</p>
<pre><code>class Classy:
def __init__(self, value):
self.var = value
variable = 1
self.new_var = variable + 1 # new_var is 2
obj1 = Classy("object")
print(obj1.var)
</code></pre>