"0 in [True,False]" returns True
Grant Edwards
grante at visi.com
Tue Dec 13 10:18:54 EST 2005
On 2005-12-13, bonono at gmail.com <bonono at gmail.com> wrote:
>
> Fredrik Lundh wrote:
>> bonono at gmail.com wrote:
>>
>> > > but seriously, unless you're writing an introspection tool, testing for
>> > > bool is pretty silly. just use "if v" or "if not v", and leave the rest to
>> > > Python.
>> > >
>> > The OP's code(and his work around) doesn't look like he is testing for
>> > boolean
>>
>> which of course explains why he wrote
>>
>> In some program I was testing if a variable was a boolean
>>
>> in the post I replied to...
>>
>> > but more like the data type of something. I thought there is some idiom
>> > in python which said something like "don't assume" ?
>>
>> "think before you post" ?
>>
> Don't know what you mean.
>
> He seems to be testing "boolean type", not whether it is true
> or false.
Right. But that's almost always pointless. Knowing whether a
variable is a boolean or not is very rarely useful. What one
wants to know is whether a varible is true or not. The code for
that is:
if v:
something
if not v:
something
--
Grant Edwards grante Yow! My DIGITAL WATCH
at has an automatic SNOOZE
visi.com FEATURE!!
More information about the Python-list
mailing list