Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libstdtypes.tex @ 22785:aa8d59823add legacy-trunk
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.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 03 Apr 2002 22:41:51 +0000 |
| parents | 7584b6f1afde |
| children | 2392af05f052 |
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex Wed Apr 03 21:52:10 2002 +0000 +++ b/Doc/lib/libstdtypes.tex Wed Apr 03 22:41:51 2002 +0000 @@ -2,10 +2,8 @@ The following sections describe the standard types that are built into the interpreter. These are the numeric types, sequence types, and -several others, including types themselves. There is no explicit -Boolean type; use integers instead. +several others, including types themselves. \indexii{built-in}{types} -\indexii{Boolean}{type} Some operations are supported by several object types; in particular, all objects can be compared, tested for truth value, and converted to @@ -30,6 +28,9 @@ \item \code{None} \withsubitem{(Built-in object)}{\ttindex{None}} +\item \code{False} + \withsubitem{(Built-in object)}{\ttindex{False}} + \item zero of any numeric type, for example, \code{0}, \code{0L}, \code{0.0}, \code{0j}. @@ -50,11 +51,12 @@ \index{true} Operations and built-in functions that have a Boolean result always -return \code{0} for false and \code{1} for true, unless otherwise -stated. (Important exception: the Boolean operations -\samp{or}\opindex{or} and \samp{and}\opindex{and} always return one of -their operands.) - +return \code{0} or \code{False} for false and \code{1} or \code{True} +for true, unless otherwise stated. (Important exception: the Boolean +operations \samp{or}\opindex{or} and \samp{and}\opindex{and} always +return one of their operands.) +\index{False} +\index{True} \subsection{Boolean Operations \label{boolean}} @@ -68,7 +70,7 @@ {if \var{x} is false, then \var{x}, else \var{y}}{(1)} \hline \lineiii{not \var{x}} - {if \var{x} is false, then \code{1}, else \code{0}}{(2)} + {if \var{x} is false, then \code{True}, else \code{False}}{(2)} \end{tableiii} \opindex{and} \opindex{or} @@ -161,8 +163,10 @@ \subsection{Numeric Types \label{typesnumeric}} -There are four numeric types: \dfn{plain integers}, \dfn{long integers}, +There are four distinct numeric types: \dfn{plain integers}, +\dfn{long integers}, \dfn{floating point numbers}, and \dfn{complex numbers}. +In addition, Booleans are a subtype of plain integers. Plain integers (also just called \dfn{integers}) are implemented using \ctype{long} in C, which gives them at least 32 bits of precision. Long integers have unlimited precision. Floating @@ -170,6 +174,7 @@ their precision are off unless you happen to know the machine you are working with. \obindex{numeric} +\obindex{Boolean} \obindex{integer} \obindex{long integer} \obindex{floating point} @@ -1389,6 +1394,22 @@ It is written as \code{Ellipsis}. +\subsubsection{Boolean Values} + +Boolean values are the two constant objects \code{False} and +\code{True}. They are used to represent truth values (although other +values can also be considered false or true). In numeric contexts +(for example when used as the argument to an arithmetic operator), +they behave like the integers 0 and 1, respectively. The built-in +function \function{bool()} can be used to cast any value to a Boolean, +if the value can be interpreted as a truth value (see section Truth +Value Testing above). + +They are written as \code{False} and \code{True}, respectively. +\index{False} +\index{True} +\indexii{Boolean}{values} + \subsubsection{Internal Objects \label{typesinternal}}
