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
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