Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{operator} --- |
| 2 | Standard operators as functions.} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 3 | \declaremodule{builtin}{operator} |
Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 4 | \sectionauthor{Skip Montanaro}{skip@automatrix.com} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 5 | |
| 6 | \modulesynopsis{All Python's standard operators as built-in functions.} |
| 7 | |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 8 | |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 9 | The \module{operator} module exports a set of functions implemented in C |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 10 | corresponding to the intrinsic operators of Python. For example, |
Fred Drake | f3e6df1 | 1997-12-29 17:11:55 +0000 | [diff] [blame] | 11 | \code{operator.add(x, y)} is equivalent to the expression \code{x+y}. The |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 12 | function names are those used for special class methods; variants without |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 13 | leading and trailing \samp{__} are also provided for convenience. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 14 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 15 | The functions fall into categories that perform object comparisons, |
| 16 | logical operations, mathematical operations, sequence operations, and |
| 17 | abstract type tests. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 18 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 19 | The object comparison functions are useful for all objects, and are |
| 20 | named after the rich comparison operators they support: |
| 21 | |
| 22 | \begin{funcdesc}{lt}{a, b} |
| 23 | \funcline{le}{a, b} |
| 24 | \funcline{eq}{a, b} |
| 25 | \funcline{ne}{a, b} |
| 26 | \funcline{ge}{a, b} |
| 27 | \funcline{gt}{a, b} |
| 28 | \funcline{__lt__}{a, b} |
| 29 | \funcline{__le__}{a, b} |
| 30 | \funcline{__eq__}{a, b} |
| 31 | \funcline{__ne__}{a, b} |
| 32 | \funcline{__ge__}{a, b} |
| 33 | \funcline{__gt__}{a, b} |
| 34 | Perform ``rich comparisons'' between \var{a} and \var{b}. Specifically, |
| 35 | \code{lt(\var{a}, \var{b})} is equivalent to \code{\var{a} < \var{b}}, |
| 36 | \code{le(\var{a}, \var{b})} is equivalent to \code{\var{a} <= \var{b}}, |
| 37 | \code{eq(\var{a}, \var{b})} is equivalent to \code{\var{a} == \var{b}}, |
| 38 | \code{ne(\var{a}, \var{b})} is equivalent to \code{\var{a} != \var{b}}, |
| 39 | \code{gt(\var{a}, \var{b})} is equivalent to \code{\var{a} > \var{b}} |
| 40 | and |
| 41 | \code{ge(\var{a}, \var{b})} is equivalent to \code{\var{a} >= \var{b}}. |
| 42 | Note that unlike the built-in \function{cmp()}, these functions can |
| 43 | return any value, which may or may not be interpretable as a Boolean |
| 44 | value. See the \citetitle[../ref/ref.html]{Python Reference Manual} |
| 45 | for more informations about rich comparisons. |
| 46 | \versionadded{2.2} |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 47 | \end{funcdesc} |
| 48 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 49 | |
| 50 | The logical operations are also generally applicable to all objects, |
| 51 | and support truth tests and Boolean operations: |
| 52 | |
| 53 | \begin{funcdesc}{not_}{o} |
| 54 | \funcline{__not__}{o} |
| 55 | Return the outcome of \keyword{not} \var{o}. (Note that there is no |
| 56 | \method{__not__()} method for object instances; only the interpreter |
| 57 | core defines this operation. The result is affected by the |
| 58 | \method{__nonzero__()} and \method{__len__()} methods.) |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 59 | \end{funcdesc} |
| 60 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 61 | \begin{funcdesc}{truth}{o} |
| 62 | Return \code{1} if \var{o} is true, and 0 otherwise. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 63 | \end{funcdesc} |
| 64 | |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 65 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 66 | The mathematical and bitwise operations are the most numerous: |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 67 | |
| 68 | \begin{funcdesc}{abs}{o} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 69 | \funcline{__abs__}{o} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 70 | Return the absolute value of \var{o}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 71 | \end{funcdesc} |
| 72 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 73 | \begin{funcdesc}{add}{a, b} |
| 74 | \funcline{__add__}{a, b} |
| 75 | Return \var{a} \code{+} \var{b}, for \var{a} and \var{b} numbers. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 76 | \end{funcdesc} |
| 77 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 78 | \begin{funcdesc}{and_}{a, b} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 79 | \funcline{__and__}{a, b} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 80 | Return the bitwise and of \var{a} and \var{b}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 81 | \end{funcdesc} |
| 82 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 83 | \begin{funcdesc}{div}{a, b} |
| 84 | \funcline{__div__}{a, b} |
| 85 | Return \var{a} \code{/} \var{b} when \code{__future__.division} is not |
| 86 | in effect. This is also known as ``classic'' division. |
| 87 | \end{funcdesc} |
| 88 | |
| 89 | \begin{funcdesc}{floordiv}{a, b} |
| 90 | \funcline{__floordiv__}{a, b} |
| 91 | Return \var{a} \code{//} \var{b}. |
| 92 | \versionadded{2.2} |
| 93 | \end{funcdesc} |
| 94 | |
| 95 | \begin{funcdesc}{inv}{o} |
| 96 | \funcline{invert}{o} |
| 97 | \funcline{__inv__}{o} |
| 98 | \funcline{__invert__}{o} |
| 99 | Return the bitwise inverse of the number \var{o}. This is equivalent |
| 100 | to \code{\textasciitilde}\var{o}. The names \function{invert()} and |
| 101 | \function{__invert__()} were added in Python 2.0. |
| 102 | \end{funcdesc} |
| 103 | |
| 104 | \begin{funcdesc}{lshift}{a, b} |
| 105 | \funcline{__lshift__}{a, b} |
| 106 | Return \var{a} shifted left by \var{b}. |
| 107 | \end{funcdesc} |
| 108 | |
| 109 | \begin{funcdesc}{mod}{a, b} |
| 110 | \funcline{__mod__}{a, b} |
| 111 | Return \var{a} \code{\%} \var{b}. |
| 112 | \end{funcdesc} |
| 113 | |
| 114 | \begin{funcdesc}{mul}{a, b} |
| 115 | \funcline{__mul__}{a, b} |
| 116 | Return \var{a} \code{*} \var{b}, for \var{a} and \var{b} numbers. |
| 117 | \end{funcdesc} |
| 118 | |
| 119 | \begin{funcdesc}{neg}{o} |
| 120 | \funcline{__neg__}{o} |
| 121 | Return \var{o} negated. |
| 122 | \end{funcdesc} |
| 123 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 124 | \begin{funcdesc}{or_}{a, b} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 125 | \funcline{__or__}{a, b} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 126 | Return the bitwise or of \var{a} and \var{b}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 127 | \end{funcdesc} |
| 128 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 129 | \begin{funcdesc}{pos}{o} |
| 130 | \funcline{__pos__}{o} |
| 131 | Return \var{o} positive. |
| 132 | \end{funcdesc} |
| 133 | |
| 134 | \begin{funcdesc}{rshift}{a, b} |
| 135 | \funcline{__rshift__}{a, b} |
| 136 | Return \var{a} shifted right by \var{b}. |
| 137 | \end{funcdesc} |
| 138 | |
| 139 | \begin{funcdesc}{sub}{a, b} |
| 140 | \funcline{__sub__}{a, b} |
| 141 | Return \var{a} \code{-} \var{b}. |
| 142 | \end{funcdesc} |
| 143 | |
| 144 | \begin{funcdesc}{truediv}{a, b} |
| 145 | \funcline{__truediv__}{a, b} |
| 146 | Return \var{a} \code{/} \var{b} when \code{__future__.division} is in |
| 147 | effect. This is also known as division. |
| 148 | \versionadded{2.2} |
| 149 | \end{funcdesc} |
| 150 | |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 151 | \begin{funcdesc}{xor}{a, b} |
| 152 | \funcline{__xor__}{a, b} |
| 153 | Return the bitwise exclusive or of \var{a} and \var{b}. |
| 154 | \end{funcdesc} |
| 155 | |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 156 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 157 | Operations which work with sequences include: |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 158 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 159 | \begin{funcdesc}{concat}{a, b} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 160 | \funcline{__concat__}{a, b} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 161 | Return \var{a} \code{+} \var{b} for \var{a} and \var{b} sequences. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 162 | \end{funcdesc} |
| 163 | |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 164 | \begin{funcdesc}{contains}{a, b} |
Fred Drake | 5316ef4 | 2000-09-17 16:10:25 +0000 | [diff] [blame] | 165 | \funcline{__contains__}{a, b} |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 166 | Return the outcome of the test \var{b} \code{in} \var{a}. |
Fred Drake | 5316ef4 | 2000-09-17 16:10:25 +0000 | [diff] [blame] | 167 | Note the reversed operands. The name \function{__contains__()} was |
| 168 | added in Python 2.0. |
| 169 | \end{funcdesc} |
| 170 | |
Guido van Rossum | a58e9ed | 1998-05-22 18:48:37 +0000 | [diff] [blame] | 171 | \begin{funcdesc}{countOf}{a, b} |
| 172 | Return the number of occurrences of \var{b} in \var{a}. |
| 173 | \end{funcdesc} |
| 174 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 175 | \begin{funcdesc}{delitem}{a, b} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 176 | \funcline{__delitem__}{a, b} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 177 | Remove the value of \var{a} at index \var{b}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 178 | \end{funcdesc} |
| 179 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 180 | \begin{funcdesc}{delslice}{a, b, c} |
| 181 | \funcline{__delslice__}{a, b, c} |
| 182 | Delete the slice of \var{a} from index \var{b} to index \var{c}\code{-1}. |
| 183 | \end{funcdesc} |
| 184 | |
| 185 | \begin{funcdesc}{getitem}{a, b} |
| 186 | \funcline{__getitem__}{a, b} |
| 187 | Return the value of \var{a} at index \var{b}. |
| 188 | \end{funcdesc} |
| 189 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 190 | \begin{funcdesc}{getslice}{a, b, c} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 191 | \funcline{__getslice__}{a, b, c} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 192 | Return the slice of \var{a} from index \var{b} to index \var{c}\code{-1}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 193 | \end{funcdesc} |
| 194 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 195 | \begin{funcdesc}{indexOf}{a, b} |
| 196 | Return the index of the first of occurrence of \var{b} in \var{a}. |
| 197 | \end{funcdesc} |
| 198 | |
| 199 | \begin{funcdesc}{repeat}{a, b} |
| 200 | \funcline{__repeat__}{a, b} |
| 201 | Return \var{a} \code{*} \var{b} where \var{a} is a sequence and |
| 202 | \var{b} is an integer. |
| 203 | \end{funcdesc} |
| 204 | |
| 205 | \begin{funcdesc}{sequenceIncludes}{\unspecified} |
| 206 | \deprecated{2.0}{Use \function{contains()} instead.} |
| 207 | Alias for \function{contains()}. |
| 208 | \end{funcdesc} |
| 209 | |
| 210 | \begin{funcdesc}{setitem}{a, b, c} |
| 211 | \funcline{__setitem__}{a, b, c} |
| 212 | Set the value of \var{a} at index \var{b} to \var{c}. |
| 213 | \end{funcdesc} |
| 214 | |
Fred Drake | 98b032a | 1997-12-04 14:20:59 +0000 | [diff] [blame] | 215 | \begin{funcdesc}{setslice}{a, b, c, v} |
Fred Drake | c07ae9f | 1998-03-08 05:56:15 +0000 | [diff] [blame] | 216 | \funcline{__setslice__}{a, b, c, v} |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 217 | Set the slice of \var{a} from index \var{b} to index \var{c}\code{-1} to the |
| 218 | sequence \var{v}. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 219 | \end{funcdesc} |
| 220 | |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 221 | |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 222 | The \module{operator} module also defines a few predicates to test the |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 223 | type of objects. \note{Be careful not to misinterpret the |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 224 | results of these functions; only \function{isCallable()} has any |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 225 | measure of reliability with instance objects. For example:} |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 226 | |
| 227 | \begin{verbatim} |
| 228 | >>> class C: |
| 229 | ... pass |
| 230 | ... |
| 231 | >>> import operator |
| 232 | >>> o = C() |
| 233 | >>> operator.isMappingType(o) |
| 234 | 1 |
| 235 | \end{verbatim} |
| 236 | |
| 237 | \begin{funcdesc}{isCallable}{o} |
| 238 | \deprecated{2.0}{Use the \function{callable()} built-in function instead.} |
| 239 | Returns true if the object \var{o} can be called like a function, |
| 240 | otherwise it returns false. True is returned for functions, bound and |
| 241 | unbound methods, class objects, and instance objects which support the |
| 242 | \method{__call__()} method. |
| 243 | \end{funcdesc} |
| 244 | |
| 245 | \begin{funcdesc}{isMappingType}{o} |
| 246 | Returns true if the object \var{o} supports the mapping interface. |
| 247 | This is true for dictionaries and all instance objects. |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 248 | \warning{There is no reliable way to test if an instance |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 249 | supports the complete mapping protocol since the interface itself is |
| 250 | ill-defined. This makes this test less useful than it otherwise might |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 251 | be.} |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 252 | \end{funcdesc} |
| 253 | |
| 254 | \begin{funcdesc}{isNumberType}{o} |
| 255 | Returns true if the object \var{o} represents a number. This is true |
| 256 | for all numeric types implemented in C, and for all instance objects. |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 257 | \warning{There is no reliable way to test if an instance |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 258 | supports the complete numeric interface since the interface itself is |
| 259 | ill-defined. This makes this test less useful than it otherwise might |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 260 | be.} |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 261 | \end{funcdesc} |
| 262 | |
| 263 | \begin{funcdesc}{isSequenceType}{o} |
| 264 | Returns true if the object \var{o} supports the sequence protocol. |
| 265 | This returns true for all objects which define sequence methods in C, |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 266 | and for all instance objects. \warning{There is no reliable |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 267 | way to test if an instance supports the complete sequence interface |
| 268 | since the interface itself is ill-defined. This makes this test less |
Fred Drake | 0aa811c | 2001-10-20 04:24:09 +0000 | [diff] [blame] | 269 | useful than it otherwise might be.} |
Fred Drake | 8d3312f | 2000-10-02 03:36:18 +0000 | [diff] [blame] | 270 | \end{funcdesc} |
| 271 | |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 272 | |
Fred Drake | 0514ce1 | 1997-12-16 14:29:48 +0000 | [diff] [blame] | 273 | Example: Build a dictionary that maps the ordinals from \code{0} to |
| 274 | \code{256} to their character equivalents. |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 275 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 276 | \begin{verbatim} |
Guido van Rossum | 61ed4db | 1996-12-06 21:22:41 +0000 | [diff] [blame] | 277 | >>> import operator |
| 278 | >>> d = {} |
| 279 | >>> keys = range(256) |
| 280 | >>> vals = map(chr, keys) |
| 281 | >>> map(operator.setitem, [d]*len(keys), keys, vals) |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 282 | \end{verbatim} |
Fred Drake | 8c2fd49 | 2000-10-22 03:19:30 +0000 | [diff] [blame] | 283 | |
| 284 | |
| 285 | \subsection{Mapping Operators to Functions \label{operator-map}} |
| 286 | |
| 287 | This table shows how abstract operations correspond to operator |
| 288 | symbols in the Python syntax and the functions in the |
| 289 | \refmodule{operator} module. |
| 290 | |
| 291 | |
| 292 | \begin{tableiii}{l|c|l}{textrm}{Operation}{Syntax}{Function} |
| 293 | \lineiii{Addition}{\code{\var{a} + \var{b}}} |
| 294 | {\code{add(\var{a}, \var{b})}} |
| 295 | \lineiii{Concatenation}{\code{\var{seq1} + \var{seq2}}} |
| 296 | {\code{concat(\var{seq1}, \var{seq2})}} |
| 297 | \lineiii{Containment Test}{\code{\var{o} in \var{seq}}} |
| 298 | {\code{contains(\var{seq}, \var{o})}} |
| 299 | \lineiii{Division}{\code{\var{a} / \var{b}}} |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 300 | {\code{div(\var{a}, \var{b}) \#} without \code{__future__.division}} |
| 301 | \lineiii{Division}{\code{\var{a} / \var{b}}} |
| 302 | {\code{truediv(\var{a}, \var{b}) \#} with \code{__future__.division}} |
| 303 | \lineiii{Division}{\code{\var{a} // \var{b}}} |
| 304 | {\code{floordiv(\var{a}, \var{b})}} |
Fred Drake | 8c2fd49 | 2000-10-22 03:19:30 +0000 | [diff] [blame] | 305 | \lineiii{Bitwise And}{\code{\var{a} \&\ \var{b}}} |
| 306 | {\code{and_(\var{a}, \var{b})}} |
| 307 | \lineiii{Bitwise Exclusive Or}{\code{\var{a} \^\ \var{b}}} |
| 308 | {\code{xor(\var{a}, \var{b})}} |
| 309 | \lineiii{Bitwise Inversion}{\code{\~{} \var{a}}} |
| 310 | {\code{invert(\var{a})}} |
| 311 | \lineiii{Bitwise Or}{\code{\var{a} | \var{b}}} |
| 312 | {\code{or_(\var{a}, \var{b})}} |
| 313 | \lineiii{Indexed Assignment}{\code{\var{o}[\var{k}] = \var{v}}} |
| 314 | {\code{setitem(\var{o}, \var{k}, \var{v})}} |
| 315 | \lineiii{Indexed Deletion}{\code{del \var{o}[\var{k}]}} |
| 316 | {\code{delitem(\var{o}, \var{k})}} |
| 317 | \lineiii{Indexing}{\code{\var{o}[\var{k}]}} |
| 318 | {\code{getitem(\var{o}, \var{k})}} |
| 319 | \lineiii{Left Shift}{\code{\var{a} <\code{<} \var{b}}} |
| 320 | {\code{lshift(\var{a}, \var{b})}} |
| 321 | \lineiii{Modulo}{\code{\var{a} \%\ \var{b}}} |
| 322 | {\code{mod(\var{a}, \var{b})}} |
| 323 | \lineiii{Multiplication}{\code{\var{a} * \var{b}}} |
| 324 | {\code{mul(\var{a}, \var{b})}} |
| 325 | \lineiii{Negation (Arithmetic)}{\code{- \var{a}}} |
| 326 | {\code{neg(\var{a})}} |
| 327 | \lineiii{Negation (Logical)}{\code{not \var{a}}} |
| 328 | {\code{not_(\var{a})}} |
| 329 | \lineiii{Right Shift}{\code{\var{a} >\code{>} \var{b}}} |
| 330 | {\code{rshift(\var{a}, \var{b})}} |
| 331 | \lineiii{Sequence Repitition}{\code{\var{seq} * \var{i}}} |
| 332 | {\code{repeat(\var{seq}, \var{i})}} |
| 333 | \lineiii{Slice Assignment}{\code{\var{seq}[\var{i}:\var{j}]} = \var{values}} |
| 334 | {\code{setslice(\var{seq}, \var{i}, \var{j}, \var{values})}} |
| 335 | \lineiii{Slice Deletion}{\code{del \var{seq}[\var{i}:\var{j}]}} |
| 336 | {\code{delslice(\var{seq}, \var{i}, \var{j})}} |
| 337 | \lineiii{Slicing}{\code{\var{seq}[\var{i}:\var{j}]}} |
| 338 | {\code{getslice(\var{seq}, \var{i}, \var{j})}} |
| 339 | \lineiii{String Formatting}{\code{\var{s} \%\ \var{o}}} |
| 340 | {\code{mod(\var{s}, \var{o})}} |
| 341 | \lineiii{Subtraction}{\code{\var{a} - \var{b}}} |
| 342 | {\code{sub(\var{a}, \var{b})}} |
| 343 | \lineiii{Truth Test}{\code{\var{o}}} |
| 344 | {\code{truth(\var{o})}} |
Fred Drake | e89659c | 2001-08-10 15:55:09 +0000 | [diff] [blame] | 345 | \lineiii{Ordering}{\code{\var{a} < \var{b}}} |
| 346 | {\code{lt(\var{a}, \var{b})}} |
| 347 | \lineiii{Ordering}{\code{\var{a} <= \var{b}}} |
| 348 | {\code{le(\var{a}, \var{b})}} |
| 349 | \lineiii{Equality}{\code{\var{a} == \var{b}}} |
| 350 | {\code{eq(\var{a}, \var{b})}} |
| 351 | \lineiii{Difference}{\code{\var{a} != \var{b}}} |
| 352 | {\code{ne(\var{a}, \var{b})}} |
| 353 | \lineiii{Ordering}{\code{\var{a} >= \var{b}}} |
| 354 | {\code{ge(\var{a}, \var{b})}} |
| 355 | \lineiii{Ordering}{\code{\var{a} > \var{b}}} |
| 356 | {\code{gt(\var{a}, \var{b})}} |
Fred Drake | 8c2fd49 | 2000-10-22 03:19:30 +0000 | [diff] [blame] | 357 | \end{tableiii} |