擅长:python、mysql、java
<blockquote>
<p>Where does the value (200) for this specific self__maxspeed come from and
why?</p>
</blockquote>
<p>它来自<code>__init__</code>方法,在调用<code>Car()</code>时调用该方法:</p>
<pre><code>self.__maxspeed = 200
</code></pre>
<p>任何时候你创建一个<code>Car</code>它的<code>maxspeed</code>值都是200,直到你将它设置为其他值为止</p>
<blockquote>
<p>And the output of car_a.setMaxSpeed(320) is 320. So the same question
here with 320.</p>
</blockquote>
<p>下面是<code>setMaxSpeed</code>函数:</p>
<pre><code>def setMaxSpeed(self,speed):
self.__maxspeed = speed
</code></pre>
<p>如您所见,它接受您传递的任何内容作为参数(320),并为其设置<code>self.__maxspeed</code>。没什么神秘的。现在<code>Car</code>的<code>maxspeed</code>值为320,直到您将其设置为其他值</p>
<blockquote>
<p>lastly, what's the function of __maxspeed = 0 and __name = ""</p>
</blockquote>
<p>它们没有任何功能。也就是说,您的代码从未将它们用于任何用途,因此它们的出现可能是一个错误,或者您有其他代码对它们进行处理,但根据您提供的代码,它们是无用的,您可以删除它们而不会产生不良影响</p>