"0 in [True,False]" returns True

Fredrik Lundh fredrik at pythonware.com
Tue Dec 13 05:39:21 EST 2005


Duncan Booth wrote:

> Another reason to have a boolean type is of course to provide a cast:
>
>    def isNameSet(self):
>       return boolean(self.name)
>
> instead of:
>
>    def isNameSet(self):
>        if self.name:
>           return True
>        else:
>           return False

given that Python already had a function for this, that wasn't
much of a reason:

>>> help(operator.truth)
Help on built-in function truth in module operator:

truth(...)
    truth(a) -- Return True if a is true, False otherwise.

(truth returned 1 or 0 in pre-boolean versions)

(btw, instead of speculating about the rationale, why don't you all
go and read Guido's PEP ?)

</F>






More information about the Python-list mailing list