In most computer programming languages, a Boolean data type is a data type with only two possible values: true or false. Related to this, Boolean (named after George Boole) may also refer to: Boolean algebra, a logical calculus of truth values or set membership.
Most programming languages, even those that do not have an explicit Boolean type, have support for Boolean algebraic operations such as conjunction (
*), disjunction (
+), equivalence (
==), exclusive or/non-equivalence (
!=), and negation (
In Python from version 2.3 forward, there is a
bool type which is a subclass of
int, the standard integer type. It has two possible values:
False, which are "special versions" of 1 and 0 respectively and behave as such in arithmetic contexts. In addition, 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. 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.