What's the difference in python between
value = getValue()
and
value = getValue
?
Using parenthesis calls the function where as not using them creates a reference to that function.
See below:
>>> def t():
... return "Hi"
...
>>> a = t
>>> a
<function t at 0x01BECA70>
>>> a = t()
>>> a
'Hi'
>>>
Here is a good link to explain further: http://docs.python.org/2/tutorial/controlflow.html (scroll down to the "defining functions" part).
value = getValue() is a function call and assignment of the return value. It means "call function getValue with no arguments and make value refer to whatever it returns".
value = getValue says "make value refer to the same function that getValue refers to".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With