Search code examples
pythonpython-3.xfunctionfunction-call

why do we put () while calling some function and some we don't in python?


df.shape #we check the shape of dataset
(1338, 7)

While calling the above shape function, we did not use () but for most of the other function we use (). why is that?

df.info()# gives the info of the dataset 

Solution

  • pandas.DataFrame.shape is not a function, it's a property, as you can see here in the definition of shape:

        @property
        def shape(self) -> Tuple[int, int]:
            ...
    

    A property is accessed (read and written) just as if it were a regular attribute of the object, so no parentheses are used.