FANDOM


Python, from version 2.3 forward, has a bool type which is a subclass of int, the standard integer type.[1] It has two possible values: True and False, which are special versions of 1 and 0 respectively and behave as such in arithmetic contexts.

Also, a numeric value of zero (integer or fractional), the null value (None), the empty string, and empty containers (i.e. lists, sets, etc.) are considered Boolean false; all other values are considered Boolean true by default.[2]

Classes can define how their instances are treated in a Boolean context through the special method __nonzero__ (Python 2) or __bool__ (Python 3). For containers, __len__ (the special method for determining the length of containers) is used if the explicit Boolean conversion method is not defined.

This article uses content from Wikipedia:Boolean


Cite error: <ref> tags exist, but no <references/> tag was found