gpt4 book ai didi

python - Python中带括号和不带括号的调用方法

转载 作者:太空宇宙 更新时间:2023-11-03 13:38:03 27 4
gpt4 key购买 nike

<分区>

我意识到有些方法应该用 () 调用,而有些则不能。我如何使用 IPython 检查是否使用括号?例如下面的文件 scratch.py​​

import numpy as np

arr = np.random.randn(5)

print arr.sort, "\n"
print arr.sort(), "\n";
print arr.shape, "\n";
print arr.shape(), "\n";

产生这个输出:

<built-in method sort of numpy.ndarray object at 0x7fb4b5312300> 

None

(5,)

Traceback (most recent call last):
File "scratch.py", line 8, in <module>
print arr.shape(), "\n";
TypeError: 'tuple' object is not callable

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com