Implicit conversion to boolean in if and while statements

Ian Kelly ian.g.kelly at gmail.com
Sun Jul 15 12:19:16 EDT 2012


On Sun, Jul 15, 2012 at 4:56 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> (For the record, I can only think of one trap for the unwary: time
> objects are false at *exactly* midnight.)

Ugh, that's irritating.  I can't think of any scenario where I would
ever want the semantics "if timeval (is not midnight):".  This
reinforces the point that if you only want to test whether you have
None, you should use "is not None" rather than relying on __bool__.



More information about the Python-list mailing list