@@ -2,10 +2,8 @@ \section{Built-in Types \label{types}}
2
2
3
3
The following sections describe the standard types that are built into
4
4
the interpreter. These are the numeric types, sequence types, and
5
- several others, including types themselves. There is no explicit
6
- Boolean type; use integers instead.
5
+ several others, including types themselves.
7
6
\indexii {built-in}{types}
8
- \indexii {Boolean}{type}
9
7
10
8
Some operations are supported by several object types; in particular,
11
9
all objects can be compared, tested for truth value, and converted to
@@ -30,6 +28,9 @@ \subsection{Truth Value Testing \label{truth}}
30
28
\item \code {None}
31
29
\withsubitem {(Built-in object)}{\ttindex {None}}
32
30
31
+ \item \code {False}
32
+ \withsubitem {(Built-in object)}{\ttindex {False}}
33
+
33
34
\item zero of any numeric type, for example, \code {0}, \code {0L},
34
35
\code {0.0}, \code {0j}.
35
36
@@ -50,11 +51,12 @@ \subsection{Truth Value Testing \label{truth}}
50
51
\index {true}
51
52
52
53
Operations and built-in functions that have a Boolean result always
53
- return \code {0} for false and \code {1} for true, unless otherwise
54
- stated. (Important exception: the Boolean operations
55
- \samp {or}\opindex {or} and \samp {and}\opindex {and} always return one of
56
- their operands.)
57
-
54
+ return \code {0} or \code {False} for false and \code {1} or \code {True}
55
+ for true, unless otherwise stated. (Important exception: the Boolean
56
+ operations \samp {or}\opindex {or} and \samp {and}\opindex {and} always
57
+ return one of their operands.)
58
+ \index {False}
59
+ \index {True}
58
60
59
61
\subsection {Boolean Operations \label {boolean } }
60
62
@@ -68,7 +70,7 @@ \subsection{Boolean Operations \label{boolean}}
68
70
{if \var {x} is false, then \var {x}, else \var {y}}{(1)}
69
71
\hline
70
72
\lineiii {not \var {x}}
71
- {if \var {x} is false, then \code {1 }, else \code {0 }}{(2)}
73
+ {if \var {x} is false, then \code {True }, else \code {False }}{(2)}
72
74
\end {tableiii }
73
75
\opindex {and}
74
76
\opindex {or}
@@ -161,15 +163,18 @@ \subsection{Comparisons \label{comparisons}}
161
163
162
164
\subsection {Numeric Types \label {typesnumeric } }
163
165
164
- There are four numeric types: \dfn {plain integers}, \dfn {long integers},
166
+ There are four distinct numeric types: \dfn {plain integers},
167
+ \dfn {long integers},
165
168
\dfn {floating point numbers}, and \dfn {complex numbers}.
169
+ In addition, Booleans are a subtype of plain integers.
166
170
Plain integers (also just called \dfn {integers})
167
171
are implemented using \ctype {long} in C, which gives them at least 32
168
172
bits of precision. Long integers have unlimited precision. Floating
169
173
point numbers are implemented using \ctype {double} in C. All bets on
170
174
their precision are off unless you happen to know the machine you are
171
175
working with.
172
176
\obindex {numeric}
177
+ \obindex {Boolean}
173
178
\obindex {integer}
174
179
\obindex {long integer}
175
180
\obindex {floating point}
@@ -1389,6 +1394,22 @@ \subsubsection{The Ellipsis Object \label{bltin-ellipsis-object}}
1389
1394
1390
1395
It is written as \code {Ellipsis}.
1391
1396
1397
+ \subsubsection {Boolean Values }
1398
+
1399
+ Boolean values are the two constant objects \code {False} and
1400
+ \code {True}. They are used to represent truth values (although other
1401
+ values can also be considered false or true). In numeric contexts
1402
+ (for example when used as the argument to an arithmetic operator),
1403
+ they behave like the integers 0 and 1, respectively. The built-in
1404
+ function \function {bool()} can be used to cast any value to a Boolean,
1405
+ if the value can be interpreted as a truth value (see section Truth
1406
+ Value Testing above).
1407
+
1408
+ They are written as \code {False} and \code {True}, respectively.
1409
+ \index {False}
1410
+ \index {True}
1411
+ \indexii {Boolean}{values}
1412
+
1392
1413
1393
1414
\subsubsection {Internal Objects \label {typesinternal } }
1394
1415
0 commit comments