python - Why does "if foo:" follow the branch even if the function foo returns False? -


def foo(a):     print("i'm foo")     return false   if foo:     print("ok") else:     print("ko") 

i run , returns ok. know, should have written if foo():.

i forget parenthesis when calling functions without parameters , need explaination result.

thanks in advance answers!

when write

 if foo:     print("ok") else:     print("ko") 

you testing if function pointer foo. defined, prints "ok" , not call function. parenthesis, call foo function , runs code.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -