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
Post a Comment