Skip to content

Instantly share code, notes, and snippets.

@lvidarte
Created November 30, 2011 22:57
Show Gist options
  • Save lvidarte/1411628 to your computer and use it in GitHub Desktop.
Save lvidarte/1411628 to your computer and use it in GitHub Desktop.
Boolean value of objects in Python
>>> 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