为什么这不是天真的预期?
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)
x
python boolean class python-2.x python-2.7
boolean ×1
class ×1
python ×1
python-2.7 ×1
python-2.x ×1