Python函数带括号与不带括号区别||datetime.munite

  • 关于函数

def run(x, y):
    d = x + y
    return d
print(run(1,2))
print(type(run(1,2)))
print(run)
print(type(run))
>> 3
>> <class 'int'>
>> <function run at 0x00000000028A5950>
>> <class 'function'>

如上运行,就明白了

调用函数带括号,返回的是函数最终结果,需要等函数运行完成;

调用函数不带括号,返回的是函数体本身所在内存地址,函数本身没有运行。

  • 关于函数与属性

“Python函数带括号与不带括号区别”这个命题本身还有另一层意思,就是类似datetime.minute后面为什么不加()

此处minute是一个属性,而非函数(当然本质上也是函数,只是细分定义为属性)。

调用函数需要加():df.function_name(p1, p2)

调用属性不用加():df.property

  • 参考

  1. Python进阶之“属性(property)”详解
  2. 对于Python中@property的理解和使用

.
.
.
2019-04-01 15:01:53写于浦东图书馆

猜你喜欢

转载自blog.csdn.net/The_Time_Runner/article/details/88948289