Implicit conversion to boolean in if and while statements

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Feb 8 17:18:12 EST 2013


MRAB wrote:

> On 2013-02-08 07:22, Steven D'Aprano wrote:

>> Prior to Python 3, the special method __bool__ was spelled __nonempty__,
>> which demonstrates Python's philosophy towards duck-typing bools.
>>
> Incorrect, it was spelled __nonzero__.

Oops, so it was. Sorry for the brain-fart.

__nonzero__ or not, nevertheless the implication still applies: all types
are meant to map to "nothing" (zero) or "not nothing" (non-zero).



-- 
Steven




More information about the Python-list mailing list