A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/065551.html below:

Booleans (was: Conditional operator in Python?)

Booleans (was: Conditional operator in Python?) Booleans (was: Conditional operator in Python?)Fredrik Lundh fredrik at pythonware.com
Fri Apr 6 13:04:15 EDT 2001
Erik Max Francis 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

>>> from operator import truth
>>> truth(0)
0
>>> truth(3)
1
>>> truth('hello')
1
>>> truth('')
0
>>> truth([])
0
>>> truth([1])
1
>>> truth(None)
0
>>> print truth.__doc__
truth(a) -- Return 1 if a is true, and 0 otherwise.

Cheers /F



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4