[Python-ideas] Programming recommendations (PEP 8) and boolean values

INADA Naoki songofacandy at gmail.com
Thu Aug 9 09:52:40 CEST 2012


In [1]: True + True
Out[1]: 2

I think Python 4 should raise ValueError.

On Thu, Aug 9, 2012 at 4:35 PM, Yuval Greenfield <ubershmekel at gmail.com> wrote:
> On Thu, Aug 9, 2012 at 10:15 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>>
>> Le 08/08/2012 16:28, Guido van Rossum a écrit :
>>
>>> I'd be strongly against changing that rule. If you don't want other
>>> types than bool, use an isinstance check. Code using "is True" is most
>>> likely a bug. (It's different for None, since that has no second value
>>> that is assumed.)
>>
>>
>> That said, I'm also curious about the answer to Michael's following
>> question:
>> “why does it say that using an identity check is worse than an equality
>> check?”
>>
>
> In python 3.2.3:
>
>     >>> 1 == True
>     True
>     >>> 13 == True
>     False
>     >>> bool(1)
>     True
>     >>> bool(13)
>     True
>     >>> 1 is True
>     False
>     >>> 13 is True
>     False
>
> To my surprise identity is actually less confusing than equality. So I agree
> with Antoine and Michael on that point.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
INADA Naoki  <songofacandy at gmail.com>



More information about the Python-ideas mailing list