为什么我们在调用一些函数时放 () 而有些我们在 python 中没有?

Rub*_*ban -1 python function function-call python-3.x

df.shape #we check the shape of dataset
(1338, 7)
Run Code Online (Sandbox Code Playgroud)

在调用上述形状函数时,我们没有使用 (),但对于大多数其他函数,我们使用 ()。这是为什么?

df.info()# gives the info of the dataset 
Run Code Online (Sandbox Code Playgroud)

Tho*_*mas 5

pandas.DataFrame.shape不是函数,而是属性,正如您在此处的定义中所见shape

    @property
    def shape(self) -> Tuple[int, int]:
        ...
Run Code Online (Sandbox Code Playgroud)

访问(读取和写入)属性就像它是对象的常规属性一样,因此不使用括号。