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