擅长:python、mysql、java
<p>原因如下:</p>
<pre><code>answer = Class2.function2(Class2, number)
</code></pre>
<p>首先,我们必须注意,以下是等价的:</p>
<pre><code>class A:
def method(self):
pass
A().method()
A.method(A())
</code></pre>
<p>我相信你想这样做:</p>
<pre><code>class2 = Class2()
answer = class2.function2(number)
</code></pre>
<p>如果我们执行上述转换,则与此相同:</p>
<pre><code>answer = Class2.function2(Class2(), number)
</code></pre>
<p>请注意,原始代码在<code>Class2</code>之后缺少<code>()</code>,这意味着不是将<code>Class2</code></em>的<em>实例传递给方法,而是将<em>类型对象</em><code>Class2</code>本身传递给方法,这没有意义</p>