isinstance(False, int)

Robert Kern robert.kern at gmail.com
Fri Mar 5 17:09:17 EST 2010


On 2010-03-05 14:58 PM, Jack Diederich wrote:
> On Fri, Mar 5, 2010 at 2:54 PM, Steven D'Aprano
> <steve at remove-this-cybersource.com.au>  wrote:
>> On Fri, 05 Mar 2010 15:01:23 -0400, Rolando Espinoza La Fuente wrote:
>>
>>> On Fri, Mar 5, 2010 at 2:32 PM, mk<mrkafk at gmail.com>  wrote:
>>>> Arnaud Delobelle wrote:
>>>>
>>>>>>>> 1 == True
>>>>>
>>>>> True
>>>>>>>>
>>>>>>>> 0 == False
>>>>>
>>>>> True
>>>>>
>>>>> So what's your question?
>>>>
>>>> Well nothing I'm just kind of bewildered: I'd expect smth like that in
>>>> Perl, but not in Python.. Although I can understand the rationale after
>>>> skimming PEP 285, I still don't like it very much.
>>>>
>>>>
>>> So, the pythonic way to check for True/False should be:
>>>
>>>>>> 1 is True
>>> False
>>
>> Why do you need to check for True/False?
>>
>
> You should never check for "is" False/True but always check for
> equality.  The reason is that many types support the equality (__eq__)
> and boolen (__bool__ in 3x) protocols.  If you check equality these
> will be invoked, if you check identity ("is") they won't.

It depends on what you're doing. mk seems to want to distinguish booleans from 
other objects from some reason.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list