Booleans (was: Conditional operator in Python?)

Moshe Zadka moshez at zadka.site.co.il
Sat Apr 7 01:50:41 EDT 2001


On Fri, 06 Apr 2001 09:36:24 -0700, Erik Max Francis <max at alcyone.com> wrote:
 
> This is true.  I would be mollified if there were a builtin operator
> that tests truth in the same way that if ...: does.  It would be named
> something like bool or boolean and would return a 0 or 1 and nothing
> else:
> 
> >>> bool(0)
> 0
> >>> bool(3)
> 1
> >>> bool('hello')
> 1
> >>> bool('')
> 0
> >>> bool([])
> 0
> >>> bool([1])
> 1
> >>> bool(None)
> 0

It's called operator.truth
-- 
"I'll be ex-DPL soon anyway so I'm        |LUKE: Is Perl better than Python?
looking for someplace else to grab power."|YODA: No...no... no. Quicker,
   -- Wichert Akkerman (on debian-private)|      easier, more seductive.
For public key, finger moshez at debian.org  |http://www.{python,debian,gnu}.org




More information about the Python-list mailing list