[Python-ideas] Programming recommendations (PEP 8) and boolean values
Yuval Greenfield
ubershmekel at gmail.com
Thu Aug 9 09:35:29 CEST 2012
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120809/8615aac9/attachment.html>
More information about the Python-ideas
mailing list