Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/liboperator.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 376ee174ecd0 |
| children | d797cfa8ca0d |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{operator} --- |
| 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 | 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 | 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 | 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} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
45 for more informations about rich comparisons. |
|
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, |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
51 and support truth tests and Boolean operations: |
|
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} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
62 Return \code{1} if \var{o} is true, and 0 otherwise. |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
63 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
64 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
65 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
66 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
|
67 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
68 \begin{funcdesc}{abs}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
69 \funcline{__abs__}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
70 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
|
71 \end{funcdesc} |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
| 6745 | 73 \begin{funcdesc}{add}{a, b} |
| 7603 | 74 \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
|
75 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
|
76 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
78 \begin{funcdesc}{and_}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
79 \funcline{__and__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
80 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
|
81 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
82 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
83 \begin{funcdesc}{div}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
84 \funcline{__div__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
85 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
|
86 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
|
87 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
88 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
89 \begin{funcdesc}{floordiv}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
90 \funcline{__floordiv__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
91 Return \var{a} \code{//} \var{b}. |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
92 \versionadded{2.2} |
|
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}{inv}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
96 \funcline{invert}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
97 \funcline{__inv__}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
98 \funcline{__invert__}{o} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
99 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
|
100 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
|
101 \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
|
102 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
103 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
104 \begin{funcdesc}{lshift}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
105 \funcline{__lshift__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
106 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
|
107 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
108 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
109 \begin{funcdesc}{mod}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
110 \funcline{__mod__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
111 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
|
112 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 |
| 6745 | 114 \begin{funcdesc}{mul}{a, b} |
| 7603 | 115 \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
|
116 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
|
117 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 \begin{funcdesc}{neg}{o} |
| 7603 | 120 \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
|
121 Return \var{o} negated. |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
124 \begin{funcdesc}{or_}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
125 \funcline{__or__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
126 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
|
127 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
128 |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 \begin{funcdesc}{pos}{o} |
| 7603 | 130 \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
|
131 Return \var{o} positive. |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
| 6745 | 134 \begin{funcdesc}{rshift}{a, b} |
| 7603 | 135 \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
|
136 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
|
137 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
139 \begin{funcdesc}{sub}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
140 \funcline{__sub__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
141 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
|
142 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
144 \begin{funcdesc}{truediv}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
145 \funcline{__truediv__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
146 Return \var{a} \code{/} \var{b} when \code{__future__.division} is in |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
147 effect. This is also known as division. |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
148 \versionadded{2.2} |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
|
8418
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
151 \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
|
152 \funcline{__xor__}{a, b} |
|
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
153 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
|
154 \end{funcdesc} |
|
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
155 |
|
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
156 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
157 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
|
158 |
| 6745 | 159 \begin{funcdesc}{concat}{a, b} |
| 7603 | 160 \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
|
161 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
|
162 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 |
|
8418
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
164 \begin{funcdesc}{contains}{a, b} |
|
14655
0228914e0c5f
Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents:
10991
diff
changeset
|
165 \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
|
166 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
|
167 Note the reversed operands. The name \function{__contains__()} was |
|
0228914e0c5f
Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents:
10991
diff
changeset
|
168 added in Python 2.0. |
|
0228914e0c5f
Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents:
10991
diff
changeset
|
169 \end{funcdesc} |
|
0228914e0c5f
Added documentation for new functions.
Fred Drake <fdrake@acm.org>
parents:
10991
diff
changeset
|
170 |
|
8418
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
171 \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
|
172 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
|
173 \end{funcdesc} |
|
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
174 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
175 \begin{funcdesc}{delitem}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
176 \funcline{__delitem__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
177 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
|
178 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
179 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
180 \begin{funcdesc}{delslice}{a, b, c} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
181 \funcline{__delslice__}{a, b, c} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
182 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
|
183 \end{funcdesc} |
|
b5ff663ee76d
Document missing functions: xor, not, truth, countOf, indexOf, and
Guido van Rossum <guido@python.org>
parents:
7877
diff
changeset
|
184 |
| 6745 | 185 \begin{funcdesc}{getitem}{a, b} |
| 7603 | 186 \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
|
187 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
|
188 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
190 \begin{funcdesc}{getslice}{a, b, c} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
191 \funcline{__getslice__}{a, b, c} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
192 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
|
193 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
194 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
195 \begin{funcdesc}{indexOf}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
196 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
|
197 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
198 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
199 \begin{funcdesc}{repeat}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
200 \funcline{__repeat__}{a, b} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
201 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
|
202 \var{b} is an integer. |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
203 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
204 |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
205 \begin{funcdesc}{sequenceIncludes}{\unspecified} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
206 \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
|
207 Alias for \function{contains()}. |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
208 \end{funcdesc} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
209 |
| 6745 | 210 \begin{funcdesc}{setitem}{a, b, c} |
| 7603 | 211 \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
|
212 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
|
213 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 |
| 6745 | 215 \begin{funcdesc}{setslice}{a, b, c, v} |
| 7603 | 216 \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
|
217 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
|
218 sequence \var{v}. |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 \end{funcdesc} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 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
|
226 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
227 \begin{verbatim} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
228 >>> class C: |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
229 ... pass |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
230 ... |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
231 >>> import operator |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
232 >>> o = C() |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
233 >>> operator.isMappingType(o) |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
234 1 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
235 \end{verbatim} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
236 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
237 \begin{funcdesc}{isCallable}{o} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
238 \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
|
239 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
|
240 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
|
241 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
|
242 \method{__call__()} method. |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
243 \end{funcdesc} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
244 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
245 \begin{funcdesc}{isMappingType}{o} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
246 Returns true if the object \var{o} supports the mapping interface. |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
247 This is true for dictionaries and all instance objects. |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
19132
diff
changeset
|
248 \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
|
249 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
|
250 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
|
251 be.} |
|
14965
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
252 \end{funcdesc} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
253 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
254 \begin{funcdesc}{isNumberType}{o} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
255 Returns true if the object \var{o} represents a number. This is true |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
256 for all numeric types implemented in C, and for all instance objects. |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
19132
diff
changeset
|
257 \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
|
258 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
|
259 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
|
260 be.} |
|
14965
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
261 \end{funcdesc} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
262 |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
263 \begin{funcdesc}{isSequenceType}{o} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
264 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
|
265 This returns true for all objects which define sequence methods in C, |
|
20580
376ee174ecd0
Use the \note and \warning macros where appropriate.
Fred Drake <fdrake@acm.org>
parents:
19132
diff
changeset
|
266 and for all instance objects. \warning{There is no reliable |
|
14965
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 \end{funcdesc} |
|
1aa37008fd2c
Add documentation and warnings for the isCallable(), isMappingType(),
Fred Drake <fdrake@acm.org>
parents:
14655
diff
changeset
|
271 |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 |
|
6876
4e2cc5044fa5
Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents:
6871
diff
changeset
|
273 Example: Build a dictionary that maps the ordinals from \code{0} to |
|
4e2cc5044fa5
Descriptions for delitem(), __delitem__(): These delete a value, not set it.
Fred Drake <fdrake@acm.org>
parents:
6871
diff
changeset
|
274 \code{256} to their character equivalents. |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
6955
diff
changeset
|
276 \begin{verbatim} |
|
4610
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 >>> import operator |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 >>> d = {} |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 >>> keys = range(256) |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 >>> vals = map(chr, keys) |
|
bb4094ff7bdf
Added section for operator module (compiled Skip Montanaro).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 >>> 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
|
282 \end{verbatim} |
|
15291
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
283 |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
284 |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
285 \subsection{Mapping Operators to Functions \label{operator-map}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
286 |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
287 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
|
288 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
|
289 \refmodule{operator} module. |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
290 |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
291 |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
292 \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
|
293 \lineiii{Addition}{\code{\var{a} + \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
294 {\code{add(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
295 \lineiii{Concatenation}{\code{\var{seq1} + \var{seq2}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
296 {\code{concat(\var{seq1}, \var{seq2})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
297 \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
|
298 {\code{contains(\var{seq}, \var{o})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
299 \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
|
300 {\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
|
301 \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
|
302 {\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
|
303 \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
|
304 {\code{floordiv(\var{a}, \var{b})}} |
|
15291
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
305 \lineiii{Bitwise And}{\code{\var{a} \&\ \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
306 {\code{and_(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
307 \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
|
308 {\code{xor(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
309 \lineiii{Bitwise Inversion}{\code{\~{} \var{a}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
310 {\code{invert(\var{a})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
311 \lineiii{Bitwise Or}{\code{\var{a} | \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
312 {\code{or_(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
313 \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
|
314 {\code{setitem(\var{o}, \var{k}, \var{v})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
315 \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
|
316 {\code{delitem(\var{o}, \var{k})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
317 \lineiii{Indexing}{\code{\var{o}[\var{k}]}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
318 {\code{getitem(\var{o}, \var{k})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
319 \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
|
320 {\code{lshift(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
321 \lineiii{Modulo}{\code{\var{a} \%\ \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
322 {\code{mod(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
323 \lineiii{Multiplication}{\code{\var{a} * \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
324 {\code{mul(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
325 \lineiii{Negation (Arithmetic)}{\code{- \var{a}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
326 {\code{neg(\var{a})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
327 \lineiii{Negation (Logical)}{\code{not \var{a}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
328 {\code{not_(\var{a})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
329 \lineiii{Right Shift}{\code{\var{a} >\code{>} \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
330 {\code{rshift(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
331 \lineiii{Sequence Repitition}{\code{\var{seq} * \var{i}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
332 {\code{repeat(\var{seq}, \var{i})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
333 \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
|
334 {\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
|
335 \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
|
336 {\code{delslice(\var{seq}, \var{i}, \var{j})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
337 \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
|
338 {\code{getslice(\var{seq}, \var{i}, \var{j})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
339 \lineiii{String Formatting}{\code{\var{s} \%\ \var{o}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
340 {\code{mod(\var{s}, \var{o})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
341 \lineiii{Subtraction}{\code{\var{a} - \var{b}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
342 {\code{sub(\var{a}, \var{b})}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
343 \lineiii{Truth Test}{\code{\var{o}}} |
|
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
344 {\code{truth(\var{o})}} |
|
19132
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
345 \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
|
346 {\code{lt(\var{a}, \var{b})}} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
347 \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
|
348 {\code{le(\var{a}, \var{b})}} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
349 \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
|
350 {\code{eq(\var{a}, \var{b})}} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
351 \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
|
352 {\code{ne(\var{a}, \var{b})}} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
353 \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
|
354 {\code{ge(\var{a}, \var{b})}} |
|
40a17d9500a8
Added documentation for the new rich comparison support.
Fred Drake <fdrake@acm.org>
parents:
15578
diff
changeset
|
355 \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
|
356 {\code{gt(\var{a}, \var{b})}} |
|
15291
1f9d5eb84b0b
Added missing entry for invert() function.
Fred Drake <fdrake@acm.org>
parents:
15061
diff
changeset
|
357 \end{tableiii} |
