annotate Doc/lib/liboperator.tex @ 39042:c02fa187e0f4 legacy-trunk

Part of SF patch #1484695. This removes dead code. The chksum was already verified in .frombuf() on the lines above. If there was a problem an exception is raised, so there was no way this condition could have been true.
author Neal Norwitz <nnorwitz@gmail.com>
date Mon, 10 Jul 2006 00:23:17 +0000
parents 6e0b053c6cf7
children 88133417dfd0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
1 \section{\module{operator} ---
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
2 Standard operators as functions.}
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8418
diff changeset
3 \declaremodule{builtin}{operator}
8918
acfffe14628e New section header style.
Fred Drake <fdrake@acm.org>
parents: 8716
diff changeset
4 \sectionauthor{Skip Montanaro}{skip@automatrix.com}
8716
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8418
diff changeset
5
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8418
diff changeset
6 \modulesynopsis{All Python's standard operators as built-in functions.}
760dcf197048 Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents: 8418
diff changeset
7
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
9 The \module{operator} module exports a set of functions implemented in C
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 corresponding to the intrinsic operators of Python. For example,
6955
38493b9376ea Remove unneeded "{}" that confused makeinfo.
Fred Drake <fdrake@acm.org>
parents: 6876
diff changeset
11 \code{operator.add(x, y)} is equivalent to the expression \code{x+y}. The
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 function names are those used for special class methods; variants without
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
13 leading and trailing \samp{__} are also provided for convenience.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
15 The functions fall into categories that perform object comparisons,
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
16 logical operations, mathematical operations, sequence operations, and
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
17 abstract type tests.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
18
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
19 The object comparison functions are useful for all objects, and are
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
20 named after the rich comparison operators they support:
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
21
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
22 \begin{funcdesc}{lt}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
23 \funcline{le}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
24 \funcline{eq}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
25 \funcline{ne}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
26 \funcline{ge}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
27 \funcline{gt}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
28 \funcline{__lt__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
29 \funcline{__le__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
30 \funcline{__eq__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
31 \funcline{__ne__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
32 \funcline{__ge__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
33 \funcline{__gt__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
34 Perform ``rich comparisons'' between \var{a} and \var{b}. Specifically,
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
35 \code{lt(\var{a}, \var{b})} is equivalent to \code{\var{a} < \var{b}},
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
36 \code{le(\var{a}, \var{b})} is equivalent to \code{\var{a} <= \var{b}},
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
37 \code{eq(\var{a}, \var{b})} is equivalent to \code{\var{a} == \var{b}},
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
38 \code{ne(\var{a}, \var{b})} is equivalent to \code{\var{a} != \var{b}},
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
39 \code{gt(\var{a}, \var{b})} is equivalent to \code{\var{a} > \var{b}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
40 and
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
41 \code{ge(\var{a}, \var{b})} is equivalent to \code{\var{a} >= \var{b}}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
42 Note that unlike the built-in \function{cmp()}, these functions can
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
43 return any value, which may or may not be interpretable as a Boolean
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
44 value. See the \citetitle[../ref/ref.html]{Python Reference Manual}
34296
67f2190e1f6d SF Patch #1093896: miscellaneous doc typos
Raymond Hettinger <python@rcn.com>
parents: 31212
diff changeset
45 for more information about rich comparisons.
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
46 \versionadded{2.2}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
47 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
48
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
49
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
50 The logical operations are also generally applicable to all objects,
28003
16b25032217f Fill in missing table entries.
Raymond Hettinger <python@rcn.com>
parents: 27290
diff changeset
51 and support truth tests, identity tests, and boolean operations:
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
52
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
53 \begin{funcdesc}{not_}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
54 \funcline{__not__}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
55 Return the outcome of \keyword{not} \var{o}. (Note that there is no
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
56 \method{__not__()} method for object instances; only the interpreter
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
57 core defines this operation. The result is affected by the
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
58 \method{__nonzero__()} and \method{__len__()} methods.)
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
59 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
60
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
61 \begin{funcdesc}{truth}{o}
27219
2ed518ab2fd2 Minor correction and clarification.
Fred Drake <fdrake@acm.org>
parents: 24904
diff changeset
62 Return \constant{True} if \var{o} is true, and \constant{False}
27223
201cdeb305f6 Try to make a sentance more readable.
Neal Norwitz <nnorwitz@gmail.com>
parents: 27219
diff changeset
63 otherwise. This is equivalent to using the \class{bool}
27219
2ed518ab2fd2 Minor correction and clarification.
Fred Drake <fdrake@acm.org>
parents: 24904
diff changeset
64 constructor.
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
65 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
66
27290
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
67 \begin{funcdesc}{is_}{a, b}
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
68 Return \code{\var{a} is \var{b}}. Tests object identity.
30840
fef6fdec5292 SF patch #834444: add versionadd to new functions
Raymond Hettinger <python@rcn.com>
parents: 28003
diff changeset
69 \versionadded{2.3}
27290
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
70 \end{funcdesc}
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
71
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
72 \begin{funcdesc}{is_not}{a, b}
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
73 Return \code{\var{a} is not \var{b}}. Tests object identity.
30840
fef6fdec5292 SF patch #834444: add versionadd to new functions
Raymond Hettinger <python@rcn.com>
parents: 28003
diff changeset
74 \versionadded{2.3}
27290
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
75 \end{funcdesc}
e83a42a90df1 SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents: 27223
diff changeset
76
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
77
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
78 The mathematical and bitwise operations are the most numerous:
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
79
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
80 \begin{funcdesc}{abs}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
81 \funcline{__abs__}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
82 Return the absolute value of \var{o}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
83 \end{funcdesc}
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
85 \begin{funcdesc}{add}{a, b}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
86 \funcline{__add__}{a, b}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
87 Return \var{a} \code{+} \var{b}, for \var{a} and \var{b} numbers.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
90 \begin{funcdesc}{and_}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
91 \funcline{__and__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
92 Return the bitwise and of \var{a} and \var{b}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
93 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
94
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
95 \begin{funcdesc}{div}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
96 \funcline{__div__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
97 Return \var{a} \code{/} \var{b} when \code{__future__.division} is not
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
98 in effect. This is also known as ``classic'' division.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
99 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
100
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
101 \begin{funcdesc}{floordiv}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
102 \funcline{__floordiv__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
103 Return \var{a} \code{//} \var{b}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
104 \versionadded{2.2}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
105 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
106
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
107 \begin{funcdesc}{inv}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
108 \funcline{invert}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
109 \funcline{__inv__}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
110 \funcline{__invert__}{o}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
111 Return the bitwise inverse of the number \var{o}. This is equivalent
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
112 to \code{\textasciitilde}\var{o}. The names \function{invert()} and
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
113 \function{__invert__()} were added in Python 2.0.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
114 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
115
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
116 \begin{funcdesc}{lshift}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
117 \funcline{__lshift__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
118 Return \var{a} shifted left by \var{b}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
119 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
120
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
121 \begin{funcdesc}{mod}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
122 \funcline{__mod__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
123 Return \var{a} \code{\%} \var{b}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
126 \begin{funcdesc}{mul}{a, b}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
127 \funcline{__mul__}{a, b}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
128 Return \var{a} \code{*} \var{b}, for \var{a} and \var{b} numbers.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 \begin{funcdesc}{neg}{o}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
132 \funcline{__neg__}{o}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
133 Return \var{o} negated.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
136 \begin{funcdesc}{or_}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
137 \funcline{__or__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
138 Return the bitwise or of \var{a} and \var{b}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
139 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
140
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 \begin{funcdesc}{pos}{o}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
142 \funcline{__pos__}{o}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
143 Return \var{o} positive.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
24887
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
146 \begin{funcdesc}{pow}{a, b}
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
147 \funcline{__pow__}{a, b}
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
148 Return \var{a} \code{**} \var{b}, for \var{a} and \var{b} numbers.
24904
641786bea13e Add versionadded for operator.pow
Neal Norwitz <nnorwitz@gmail.com>
parents: 24887
diff changeset
149 \versionadded{2.3}
24887
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
150 \end{funcdesc}
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
151
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
152 \begin{funcdesc}{rshift}{a, b}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
153 \funcline{__rshift__}{a, b}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
154 Return \var{a} shifted right by \var{b}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
157 \begin{funcdesc}{sub}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
158 \funcline{__sub__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
159 Return \var{a} \code{-} \var{b}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
162 \begin{funcdesc}{truediv}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
163 \funcline{__truediv__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
164 Return \var{a} \code{/} \var{b} when \code{__future__.division} is in
36151
Armin Rigo <arigo@tunes.org>
parents: 34875
diff changeset
165 effect. This is also known as ``true'' division.
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
166 \versionadded{2.2}
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
169 \begin{funcdesc}{xor}{a, b}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
170 \funcline{__xor__}{a, b}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
171 Return the bitwise exclusive or of \var{a} and \var{b}.
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
172 \end{funcdesc}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
173
36882
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36152
diff changeset
174 \begin{funcdesc}{index}{a}
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36152
diff changeset
175 \funcline{__index__}{a}
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36152
diff changeset
176 Return \var{a} converted to an integer. Equivalent to \var{a}\code{.__index__()}.
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36152
diff changeset
177 \versionadded{2.5}
6a9c7165b17b Checking in the code for PEP 357.
Guido van Rossum <guido@python.org>
parents: 36152
diff changeset
178 \end{funcdesc}
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
179
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
180 Operations which work with sequences include:
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
181
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
182 \begin{funcdesc}{concat}{a, b}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
183 \funcline{__concat__}{a, b}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
184 Return \var{a} \code{+} \var{b} for \var{a} and \var{b} sequences.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
186
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
187 \begin{funcdesc}{contains}{a, b}
14655
0228914e0c5f Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents: 10991
diff changeset
188 \funcline{__contains__}{a, b}
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
189 Return the outcome of the test \var{b} \code{in} \var{a}.
14655
0228914e0c5f Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents: 10991
diff changeset
190 Note the reversed operands. The name \function{__contains__()} was
0228914e0c5f Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents: 10991
diff changeset
191 added in Python 2.0.
0228914e0c5f Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents: 10991
diff changeset
192 \end{funcdesc}
0228914e0c5f Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents: 10991
diff changeset
193
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
194 \begin{funcdesc}{countOf}{a, b}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
195 Return the number of occurrences of \var{b} in \var{a}.
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
196 \end{funcdesc}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
197
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
198 \begin{funcdesc}{delitem}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
199 \funcline{__delitem__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
200 Remove the value of \var{a} at index \var{b}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
201 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
202
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
203 \begin{funcdesc}{delslice}{a, b, c}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
204 \funcline{__delslice__}{a, b, c}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
205 Delete the slice of \var{a} from index \var{b} to index \var{c}\code{-1}.
8418
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
206 \end{funcdesc}
b5ff663ee76d Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents: 7877
diff changeset
207
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
208 \begin{funcdesc}{getitem}{a, b}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
209 \funcline{__getitem__}{a, b}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
210 Return the value of \var{a} at index \var{b}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
211 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
212
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
213 \begin{funcdesc}{getslice}{a, b, c}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
214 \funcline{__getslice__}{a, b, c}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
215 Return the slice of \var{a} from index \var{b} to index \var{c}\code{-1}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
216 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
217
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
218 \begin{funcdesc}{indexOf}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
219 Return the index of the first of occurrence of \var{b} in \var{a}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
220 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
221
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
222 \begin{funcdesc}{repeat}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
223 \funcline{__repeat__}{a, b}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
224 Return \var{a} \code{*} \var{b} where \var{a} is a sequence and
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
225 \var{b} is an integer.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
226 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
227
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
228 \begin{funcdesc}{sequenceIncludes}{\unspecified}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
229 \deprecated{2.0}{Use \function{contains()} instead.}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
230 Alias for \function{contains()}.
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
231 \end{funcdesc}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
232
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
233 \begin{funcdesc}{setitem}{a, b, c}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
234 \funcline{__setitem__}{a, b, c}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
235 Set the value of \var{a} at index \var{b} to \var{c}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
237
6745
1db41ca45c7f Removed unnecessary escaping.
Fred Drake <fdrake@acm.org>
parents: 5818
diff changeset
238 \begin{funcdesc}{setslice}{a, b, c, v}
7603
c0bf9b60c298 Some logical markup.
Fred Drake <fdrake@acm.org>
parents: 7343
diff changeset
239 \funcline{__setslice__}{a, b, c, v}
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
240 Set the slice of \var{a} from index \var{b} to index \var{c}\code{-1} to the
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
241 sequence \var{v}.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
242 \end{funcdesc}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
243
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
244
36152
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
245 Many operations have an ``in-place'' version. The following functions
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
246 provide a more primitive access to in-place operators than the usual
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
247 syntax does; for example, the statement \code{x += y} is equivalent to
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
248 \code{x = operator.iadd(x, y)}. Another way to put it is to say that
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
249 \code{z = operator.iadd(x, y)} is equivalent to the compound statement
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
250 \code{z = x; z += y}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
251
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
252 \begin{funcdesc}{iadd}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
253 \funcline{__iadd__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
254 \code{a = iadd(a, b)} is equivalent to \code{a += b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
255 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
256 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
257
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
258 \begin{funcdesc}{iand}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
259 \funcline{__iand__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
260 \code{a = iand(a, b)} is equivalent to \code{a \&= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
261 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
262 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
263
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
264 \begin{funcdesc}{iconcat}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
265 \funcline{__iconcat__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
266 \code{a = iconcat(a, b)} is equivalent to \code{a += b} for \var{a}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
267 and \var{b} sequences.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
268 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
269 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
270
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
271 \begin{funcdesc}{idiv}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
272 \funcline{__idiv__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
273 \code{a = idiv(a, b)} is equivalent to \code{a /= b} when
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
274 \code{__future__.division} is not in effect.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
275 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
276 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
277
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
278 \begin{funcdesc}{ifloordiv}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
279 \funcline{__ifloordiv__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
280 \code{a = ifloordiv(a, b)} is equivalent to \code{a //= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
281 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
282 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
283
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
284 \begin{funcdesc}{ilshift}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
285 \funcline{__ilshift__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
286 \code{a = ilshift(a, b)} is equivalent to \code{a <}\code{<= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
287 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
288 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
289
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
290 \begin{funcdesc}{imod}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
291 \funcline{__imod__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
292 \code{a = imod(a, b)} is equivalent to \code{a \%= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
293 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
294 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
295
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
296 \begin{funcdesc}{imul}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
297 \funcline{__imul__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
298 \code{a = imul(a, b)} is equivalent to \code{a *= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
299 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
300 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
301
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
302 \begin{funcdesc}{ior}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
303 \funcline{__ior__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
304 \code{a = ior(a, b)} is equivalent to \code{a |= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
305 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
306 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
307
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
308 \begin{funcdesc}{ipow}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
309 \funcline{__ipow__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
310 \code{a = ipow(a, b)} is equivalent to \code{a **= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
311 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
312 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
313
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
314 \begin{funcdesc}{irepeat}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
315 \funcline{__irepeat__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
316 \code{a = irepeat(a, b)} is equivalent to \code{a *= b} where
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
317 \var{a} is a sequence and \var{b} is an integer.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
318 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
319 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
320
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
321 \begin{funcdesc}{irshift}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
322 \funcline{__irshift__}{a, b}
38091
6e0b053c6cf7 avoid ugly markup based on the unfortunate conversions of ">>" and "<<" to
Fred Drake <fdrake@acm.org>
parents: 36882
diff changeset
323 \code{a = irshift(a, b)} is equivalent to \code{a >>= b}.
36152
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
324 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
325 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
326
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
327 \begin{funcdesc}{isub}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
328 \funcline{__isub__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
329 \code{a = isub(a, b)} is equivalent to \code{a -= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
330 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
331 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
332
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
333 \begin{funcdesc}{itruediv}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
334 \funcline{__itruediv__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
335 \code{a = itruediv(a, b)} is equivalent to \code{a /= b} when
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
336 \code{__future__.division} is in effect.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
337 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
338 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
339
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
340 \begin{funcdesc}{ixor}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
341 \funcline{__ixor__}{a, b}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
342 \code{a = ixor(a, b)} is equivalent to \code{a \textasciicircum= b}.
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
343 \versionadded{2.5}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
344 \end{funcdesc}
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
345
f9281283b109 adding in-place operators to the operator module.
Armin Rigo <arigo@tunes.org>
parents: 36151
diff changeset
346
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
347 The \module{operator} module also defines a few predicates to test the
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
348 type of objects. \note{Be careful not to misinterpret the
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
349 results of these functions; only \function{isCallable()} has any
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
350 measure of reliability with instance objects. For example:}
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
351
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
352 \begin{verbatim}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
353 >>> class C:
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
354 ... pass
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
355 ...
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
356 >>> import operator
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
357 >>> o = C()
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
358 >>> operator.isMappingType(o)
31029
ce07118ee5d2 Patch #849350: Update to document bool return values. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents: 30840
diff changeset
359 True
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
360 \end{verbatim}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
361
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
362 \begin{funcdesc}{isCallable}{o}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
363 \deprecated{2.0}{Use the \function{callable()} built-in function instead.}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
364 Returns true if the object \var{o} can be called like a function,
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
365 otherwise it returns false. True is returned for functions, bound and
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
366 unbound methods, class objects, and instance objects which support the
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
367 \method{__call__()} method.
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
368 \end{funcdesc}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
369
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
370 \begin{funcdesc}{isMappingType}{o}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
371 Returns true if the object \var{o} supports the mapping interface.
34875
20b3c723502a SF bug #1178269 Clarify when isMappingType/isSequenceType is True.
Raymond Hettinger <python@rcn.com>
parents: 34873
diff changeset
372 This is true for dictionaries and all instance objects defining
20b3c723502a SF bug #1178269 Clarify when isMappingType/isSequenceType is True.
Raymond Hettinger <python@rcn.com>
parents: 34873
diff changeset
373 \method{__getitem__}.
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
374 \warning{There is no reliable way to test if an instance
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
375 supports the complete mapping protocol since the interface itself is
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
376 ill-defined. This makes this test less useful than it otherwise might
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
377 be.}
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
378 \end{funcdesc}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
379
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
380 \begin{funcdesc}{isNumberType}{o}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
381 Returns true if the object \var{o} represents a number. This is true
34875
20b3c723502a SF bug #1178269 Clarify when isMappingType/isSequenceType is True.
Raymond Hettinger <python@rcn.com>
parents: 34873
diff changeset
382 for all numeric types implemented in C.
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
383 \warning{There is no reliable way to test if an instance
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
384 supports the complete numeric interface since the interface itself is
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
385 ill-defined. This makes this test less useful than it otherwise might
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
386 be.}
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
387 \end{funcdesc}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
388
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
389 \begin{funcdesc}{isSequenceType}{o}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
390 Returns true if the object \var{o} supports the sequence protocol.
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
391 This returns true for all objects which define sequence methods in C,
34875
20b3c723502a SF bug #1178269 Clarify when isMappingType/isSequenceType is True.
Raymond Hettinger <python@rcn.com>
parents: 34873
diff changeset
392 and for all instance objects defining \method{__getitem__}.
20b3c723502a SF bug #1178269 Clarify when isMappingType/isSequenceType is True.
Raymond Hettinger <python@rcn.com>
parents: 34873
diff changeset
393 \warning{There is no reliable
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
394 way to test if an instance supports the complete sequence interface
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
395 since the interface itself is ill-defined. This makes this test less
20580
376ee174ecd0 Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents: 19132
diff changeset
396 useful than it otherwise might be.}
14965
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
397 \end{funcdesc}
1aa37008fd2c Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents: 14655
diff changeset
398
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
399
6876
4e2cc5044fa5 Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents: 6871
diff changeset
400 Example: Build a dictionary that maps the ordinals from \code{0} to
34873
18dc9158160d SF bug #1178255: 256 should read 255 in operator module docs
Raymond Hettinger <python@rcn.com>
parents: 34716
diff changeset
401 \code{255} to their character equivalents.
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
402
7277
bf4e790bd61a Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents: 6955
diff changeset
403 \begin{verbatim}
4610
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
404 >>> import operator
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 >>> d = {}
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 >>> keys = range(256)
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 >>> vals = map(chr, keys)
bb4094ff7bdf Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 >>> map(operator.setitem, [d]*len(keys), keys, vals)
7277
bf4e790bd61a Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents: 6955
diff changeset
409 \end{verbatim}
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
410
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
411
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
412 The \module{operator} module also defines tools for generalized attribute
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
413 and item lookups. These are useful for making fast field extractors
31212
5b035e6e44dc Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents: 31052
diff changeset
414 as arguments for \function{map()}, \function{sorted()},
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
415 \method{itertools.groupby()}, or other functions that expect a
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
416 function argument.
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
417
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
418 \begin{funcdesc}{attrgetter}{attr\optional{, args...}}
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
419 Return a callable object that fetches \var{attr} from its operand.
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
420 If more than one attribute is requested, returns a tuple of attributes.
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
421 After, \samp{f=attrgetter('name')}, the call \samp{f(b)} returns
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
422 \samp{b.name}. After, \samp{f=attrgetter('name', 'date')}, the call
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
423 \samp{f(b)} returns \samp{(b.name, b.date)}.
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
424 \versionadded{2.4}
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
425 \versionchanged[Added support for multiple attributes]{2.5}
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
426 \end{funcdesc}
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
427
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
428 \begin{funcdesc}{itemgetter}{item\optional{, args...}}
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
429 Return a callable object that fetches \var{item} from its operand.
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
430 If more than one item is requested, returns a tuple of items.
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
431 After, \samp{f=itemgetter(2)}, the call \samp{f(b)} returns
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
432 \samp{b[2]}.
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
433 After, \samp{f=itemgetter(2,5,3)}, the call \samp{f(b)} returns
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
434 \samp{(b[2], b[5], b[3])}.
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
435 \versionadded{2.4}
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
436 \versionchanged[Added support for multiple item extraction]{2.5}
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
437 \end{funcdesc}
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
438
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
439 Examples:
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
440
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
441 \begin{verbatim}
34716
ddc2276c247e operator.itemgetter() and operator.attrgetter() now support extraction
Raymond Hettinger <python@rcn.com>
parents: 34296
diff changeset
442 >>> from operator import itemgetter
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
443 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
444 >>> getcount = itemgetter(1)
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
445 >>> map(getcount, inventory)
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
446 [3, 2, 5, 1]
31212
5b035e6e44dc Guido grants a Christmas wish:
Raymond Hettinger <python@rcn.com>
parents: 31052
diff changeset
447 >>> sorted(inventory, key=getcount)
31052
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
448 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
449 \end{verbatim}
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
450
456e274f8602 As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents: 31029
diff changeset
451
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
452 \subsection{Mapping Operators to Functions \label{operator-map}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
453
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
454 This table shows how abstract operations correspond to operator
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
455 symbols in the Python syntax and the functions in the
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
456 \refmodule{operator} module.
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
457
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
458
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
459 \begin{tableiii}{l|c|l}{textrm}{Operation}{Syntax}{Function}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
460 \lineiii{Addition}{\code{\var{a} + \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
461 {\code{add(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
462 \lineiii{Concatenation}{\code{\var{seq1} + \var{seq2}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
463 {\code{concat(\var{seq1}, \var{seq2})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
464 \lineiii{Containment Test}{\code{\var{o} in \var{seq}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
465 {\code{contains(\var{seq}, \var{o})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
466 \lineiii{Division}{\code{\var{a} / \var{b}}}
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
467 {\code{div(\var{a}, \var{b}) \#} without \code{__future__.division}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
468 \lineiii{Division}{\code{\var{a} / \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
469 {\code{truediv(\var{a}, \var{b}) \#} with \code{__future__.division}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
470 \lineiii{Division}{\code{\var{a} // \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
471 {\code{floordiv(\var{a}, \var{b})}}
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
472 \lineiii{Bitwise And}{\code{\var{a} \&\ \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
473 {\code{and_(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
474 \lineiii{Bitwise Exclusive Or}{\code{\var{a} \^\ \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
475 {\code{xor(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
476 \lineiii{Bitwise Inversion}{\code{\~{} \var{a}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
477 {\code{invert(\var{a})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
478 \lineiii{Bitwise Or}{\code{\var{a} | \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
479 {\code{or_(\var{a}, \var{b})}}
24887
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
480 \lineiii{Exponentiation}{\code{\var{a} ** \var{b}}}
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 20580
diff changeset
481 {\code{pow(\var{a}, \var{b})}}
28003
16b25032217f Fill in missing table entries.
Raymond Hettinger <python@rcn.com>
parents: 27290
diff changeset
482 \lineiii{Identity}{\code{\var{a} is \var{b}}}
16b25032217f Fill in missing table entries.
Raymond Hettinger <python@rcn.com>
parents: 27290
diff changeset
483 {\code{is_(\var{a}, \var{b})}}
16b25032217f Fill in missing table entries.
Raymond Hettinger <python@rcn.com>
parents: 27290
diff changeset
484 \lineiii{Identity}{\code{\var{a} is not \var{b}}}
16b25032217f Fill in missing table entries.
Raymond Hettinger <python@rcn.com>
parents: 27290
diff changeset
485 {\code{is_not(\var{a}, \var{b})}}
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
486 \lineiii{Indexed Assignment}{\code{\var{o}[\var{k}] = \var{v}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
487 {\code{setitem(\var{o}, \var{k}, \var{v})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
488 \lineiii{Indexed Deletion}{\code{del \var{o}[\var{k}]}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
489 {\code{delitem(\var{o}, \var{k})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
490 \lineiii{Indexing}{\code{\var{o}[\var{k}]}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
491 {\code{getitem(\var{o}, \var{k})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
492 \lineiii{Left Shift}{\code{\var{a} <\code{<} \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
493 {\code{lshift(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
494 \lineiii{Modulo}{\code{\var{a} \%\ \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
495 {\code{mod(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
496 \lineiii{Multiplication}{\code{\var{a} * \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
497 {\code{mul(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
498 \lineiii{Negation (Arithmetic)}{\code{- \var{a}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
499 {\code{neg(\var{a})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
500 \lineiii{Negation (Logical)}{\code{not \var{a}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
501 {\code{not_(\var{a})}}
38091
6e0b053c6cf7 avoid ugly markup based on the unfortunate conversions of ">>" and "<<" to
Fred Drake <fdrake@acm.org>
parents: 36882
diff changeset
502 \lineiii{Right Shift}{\code{\var{a} >> \var{b}}}
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
503 {\code{rshift(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
504 \lineiii{Sequence Repitition}{\code{\var{seq} * \var{i}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
505 {\code{repeat(\var{seq}, \var{i})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
506 \lineiii{Slice Assignment}{\code{\var{seq}[\var{i}:\var{j}]} = \var{values}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
507 {\code{setslice(\var{seq}, \var{i}, \var{j}, \var{values})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
508 \lineiii{Slice Deletion}{\code{del \var{seq}[\var{i}:\var{j}]}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
509 {\code{delslice(\var{seq}, \var{i}, \var{j})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
510 \lineiii{Slicing}{\code{\var{seq}[\var{i}:\var{j}]}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
511 {\code{getslice(\var{seq}, \var{i}, \var{j})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
512 \lineiii{String Formatting}{\code{\var{s} \%\ \var{o}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
513 {\code{mod(\var{s}, \var{o})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
514 \lineiii{Subtraction}{\code{\var{a} - \var{b}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
515 {\code{sub(\var{a}, \var{b})}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
516 \lineiii{Truth Test}{\code{\var{o}}}
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
517 {\code{truth(\var{o})}}
19132
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
518 \lineiii{Ordering}{\code{\var{a} < \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
519 {\code{lt(\var{a}, \var{b})}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
520 \lineiii{Ordering}{\code{\var{a} <= \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
521 {\code{le(\var{a}, \var{b})}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
522 \lineiii{Equality}{\code{\var{a} == \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
523 {\code{eq(\var{a}, \var{b})}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
524 \lineiii{Difference}{\code{\var{a} != \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
525 {\code{ne(\var{a}, \var{b})}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
526 \lineiii{Ordering}{\code{\var{a} >= \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
527 {\code{ge(\var{a}, \var{b})}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
528 \lineiii{Ordering}{\code{\var{a} > \var{b}}}
40a17d9500a8 Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents: 15578
diff changeset
529 {\code{gt(\var{a}, \var{b})}}
15291
1f9d5eb84b0b Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents: 15061
diff changeset
530 \end{tableiii}