擅长:python、mysql、java
<blockquote>
<p>What's the logic behind which commands use a () and which do not?</p>
</blockquote>
<p>一个对象需要有一个与之关联的<a href="https://docs.python.org/3/reference/datamodel.html#object.__call__" rel="nofollow noreferrer">^{<cd1>}</a>方法,以便使用<code>()</code>将其作为函数调用:</p>
<pre><code>class Test:
def __call__(self, arg):
print("Called with", arg)
t = Test() # The Test class object uses __call__ to create instances
t(5) # Then this line prints "Called with 5"
</code></pre>
<p>因此,区别在于<code>columns</code>没有定义<code>__call__</code>方法,而<code>Index</code>和<code>DataFrame</code>有</p>