diff options
author | Guido van Rossum <guido@python.org> | 2002-04-03 22:41:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-04-03 22:41:51 (GMT) |
commit | 77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd (patch) | |
tree | e92163095e7ae548c36cea459dad87db74a413ef /Doc/ref | |
parent | e9c0358bf45bd6e0fe0b17720b41d20d618e6d9d (diff) | |
download | cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.zip cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.tar.gz cpython-77f6a65eb00f005939c6c7c5d6ac0f037a0ce1bd.tar.bz2 |
Add the 'bool' type and its values 'False' and 'True', as described in
PEP 285. Everything described in the PEP is here, and there is even
some documentation. I had to fix 12 unit tests; all but one of these
were printing Boolean outcomes that changed from 0/1 to False/True.
(The exception is test_unicode.py, which did a type(x) == type(y)
style comparison. I could've fixed that with a single line using
issubtype(x, type(y)), but instead chose to be explicit about those
places where a bool is expected.
Still to do: perhaps more documentation; change standard library
modules to return False/True from predicates.
Diffstat (limited to 'Doc/ref')
-rw-r--r-- | Doc/ref/ref3.tex | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex index d355b69..2056a6c 100644 --- a/Doc/ref/ref3.tex +++ b/Doc/ref/ref3.tex @@ -162,7 +162,7 @@ complex numbers: These represent elements from the mathematical set of whole numbers. \obindex{integer} -There are two types of integers: +There are three types of integers: \begin{description} @@ -187,6 +187,17 @@ represented in a variant of 2's complement which gives the illusion of an infinite string of sign bits extending to the left. \obindex{long integer} +\item[Booleans] +These represent the truth values False and True. The two objects +representing the values False and True are the only Boolean objects. +The Boolean type is a subtype of plain integers, and Boolean values +behave like the values 0 and 1, respectively, in almost all contexts, +the exception being that when converted to a string, the strings +\code{"False"} or \code{"True"} are returned, respectively. +\obindex{Boolean} +\ttindex{False} +\ttindex{True} + \end{description} % Integers The rules for integer representation are intended to give the most @@ -222,6 +233,7 @@ and \code{z.imag}. \end{description} % Numbers + \item[Sequences] These represent finite ordered sets indexed by non-negative numbers. The built-in function \function{len()}\bifuncindex{len} returns the @@ -1074,8 +1086,10 @@ wrong hash bucket). \end{methoddesc} \begin{methoddesc}[object]{__nonzero__}{self} -Called to implement truth value testing; should return \code{0} or -\code{1}. When this method is not defined, \method{__len__()} is +Called to implement truth value testing, and the built-in operation +\code{bool()}; should return \code{False} or \code{True}, or their +integer equivalents \code{0} or \code{1}. +When this method is not defined, \method{__len__()} is called, if it is defined (see below). If a class defines neither \method{__len__()} nor \method{__nonzero__()}, all its instances are considered true. |