ACCEPTED: PEP 285

Guido van Rossum guido at python.org
Thu Apr 4 09:27:51 EST 2002


> "Guido van Rossum" <guido at python.org> wrote in message
> >     This PEP does *not* change the fact that almost all object types
> >     can be used as truth values.  For example, when used in an if
> >     statement, an empty list is false and a non-empty one is true;
> >     this does not change and there is no plan to ever change this.
> 
Terry Reedy wrote:
> almost? all?  I am under the impression that 'if x:' is universally
> valid, and consider that one of the good features of Python's prime
> dichotomy system.

It's possible for a class or type to explicitly resist being used
in a Boolean context:

    class C:
        def __nonzero__(self):
            raise TypeError, "I am *not* Boolean!"

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-list mailing list