What is the difference between calling function with parentheses and without in python?

前端 未结 5 1838
心在旅途
心在旅途 2020-12-01 20:15

I have a question. Lets assume that we have function hello(). What is the difference between calling it with parentheses and without? When I call hello() it is referring to

5条回答
  •  渐次进展
    2020-12-01 20:46

    hello refers to the function object, hello() calls the function itself.

    For example:

    >>> def hello():
    ...     print "hello"
    ... 
    >>> hello
    
    >>> hello()
    hello
    

提交回复
热议问题