Created
November 30, 2011 22:57
-
-
Save lvidarte/1411628 to your computer and use it in GitHub Desktop.
Boolean value of objects in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Foo: | |
... def __init__(self, value): | |
... self.value = value | |
... def __nonzero__(self): | |
... return self.value | |
... | |
>>> a = Foo(1) | |
>>> b = Foo(0) | |
>>> assert a | |
>>> assert b | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
AssertionError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment