Name

__nonzero__

Synopsis

__nonzero__(self)

When evaluating x as true or false (see Section 4.2.6), for example on a call to bool( x ) in Python 2.2.1 and later, Python calls x .__nonzero__( ), which should return True or False. When __nonzero__ is not present, Python calls __len__ instead, and takes x as false when x .__len__( ) returns 0. When neither __nonzero__ nor __len__ is present, Python always takes x as true.

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.