【发布时间】:2012-01-02 13:59:14
【问题描述】:
为什么这不能像人们天真的预期的那样工作?
class Foo(object):
def __init__(self):
self.bar = 3
def __bool__(self):
return self.bar > 10
foo = Foo()
if foo:
print 'x'
else:
print 'y'
(输出为x)
【问题讨论】:
标签: python python-2.7 class boolean python-2.x