Boolean tests [was Re: Attack a sacred Python Cow]

Erik Max Francis max at alcyone.com
Wed Jul 30 02:09:16 EDT 2008


Carl Banks wrote:

> On Jul 30, 1:15 am, "Russ P." <Russ.Paie... at gmail.com> wrote:
>> All this discussion about "if x" has me wondering. I use it all the
>> time because a fully explicit test just seems redundant. But maybe it
>> does have some value in terms of readability and type checking. After
>> all, it is possible to forget whether something is a number or a list.
> 
> IMO, the only time I think "if x" is really dangerous is if you are
> using "if x" instead of "if x is None" to distinguish between None and
> a type that can have false values.

Well, that would be an exceptionally bad way to test for None-ness, 
since None is false.  The test would never succeed.

>> Having said that, it would sure be nice to be able to write
>>
>> if myList is not empty:
>>
>> instead of
>>
>> if len(myList) != 0:
> 
> I can agree with this.

I'm getting this sneaking suspicion that you guys are all putting us on.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
   The doors of Heaven and Hell are adjacent and identical.
    -- Nikos Kazantzakis



More information about the Python-list mailing list