In python, the value of a function object (I don't know ...) is True. Confirmed in 2.7.
def func():
return False
if func:
print('true')
else:
print('false')
# true
if func():
print('true')
else:
print('false')
# false
class Test(object):
def __init__(self):
self._flag = False
#here@I intended to add property but forgot to add it
def flag(self):
print('test flag')
return self._flag
# ---
if __name__ == '__main__':
test = Test()
#I think it's a property, so call it without parentheses
if test.flag:
print('true')
else:
print('false')
# 'test flag'Is not printed
# 'true'Only printed
It's a mistake, but isn't it? No, I'm just too shobo ...
Recommended Posts