Why bool( object )?
Scott David Daniels
Scott.Daniels at Acm.Org
Tue Apr 28 12:44:13 EDT 2009
Steven D'Aprano wrote:
> On Mon, 27 Apr 2009 23:11:11 -0700, Aaron Brady wrote:
>... In a boolean (or truth) context, Something and Nothing behave like True
> and False in languages with real booleans:
> if obj:
> print "I am Something"
> else:
> print "I am Nothing"
If you define the short-circuit boolean operators "and" and "or" as
Python does, the idea of "most anything is True" menas you can have
code that does:
v = look('here') or look('there') or look('everywhere') or default
This is a nice idiom, and the "or default" can be used in lots of cases.
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list