Python中函数带括号和不带括号的区别

#python3.5


def a(x):
      return x

print(a)    #不带括号调用的结果:<function a at 0x1091766a8>
print(a(3)) #带括号调用的结果:3
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

1、不带括号时,调用的是这个函数本身 
2、带括号(此时必须传入需要的参数),调用的是函数的return结果

猜你喜欢

转载自blog.csdn.net/com_ma/article/details/81013474