blob: 650b3df5df29829620c21883bb3487ea46c6aaf2 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`operator` --- Standard operators as functions
2===================================================
3
4.. module:: operator
5 :synopsis: Functions corresponding to the standard operators.
6.. sectionauthor:: Skip Montanaro <skip@automatrix.com>
7
8
Christian Heimesfe337bf2008-03-23 21:54:12 +00009.. testsetup::
Georg Brandl48310cd2009-01-03 21:18:54 +000010
Christian Heimesfe337bf2008-03-23 21:54:12 +000011 import operator
Alexander Belopolsky287d1fd2011-01-12 16:37:14 +000012 from operator import itemgetter, iadd
Christian Heimesfe337bf2008-03-23 21:54:12 +000013
Georg Brandl116aa622007-08-15 14:28:22 +000014
Benjamin Peterson0f1e3ac2011-12-20 10:12:41 -060015The :mod:`operator` module exports a set of efficient functions corresponding to
16the intrinsic operators of Python. For example, ``operator.add(x, y)`` is
Benjamin Peterson1c92cfe2011-12-19 16:41:11 -050017equivalent to the expression ``x+y``. The function names are those used for
18special class methods; variants without leading and trailing ``__`` are also
19provided for convenience.
Georg Brandl116aa622007-08-15 14:28:22 +000020
21The functions fall into categories that perform object comparisons, logical
Georg Brandlb30f3302011-01-06 09:23:56 +000022operations, mathematical operations and sequence operations.
Georg Brandl116aa622007-08-15 14:28:22 +000023
24The object comparison functions are useful for all objects, and are named after
25the rich comparison operators they support:
26
27
28.. function:: lt(a, b)
29 le(a, b)
30 eq(a, b)
31 ne(a, b)
32 ge(a, b)
33 gt(a, b)
34 __lt__(a, b)
35 __le__(a, b)
36 __eq__(a, b)
37 __ne__(a, b)
38 __ge__(a, b)
39 __gt__(a, b)
40
41 Perform "rich comparisons" between *a* and *b*. Specifically, ``lt(a, b)`` is
42 equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
43 b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
44 ``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
Mark Dickinsonc48d8342009-02-01 14:18:10 +000045 >= b``. Note that these functions can return any value, which may
46 or may not be interpretable as a Boolean value. See
47 :ref:`comparisons` for more information about rich comparisons.
Georg Brandl116aa622007-08-15 14:28:22 +000048
Georg Brandl116aa622007-08-15 14:28:22 +000049
50The logical operations are also generally applicable to all objects, and support
51truth tests, identity tests, and boolean operations:
52
53
Thomas Wouters1b7f8912007-09-19 03:06:30 +000054.. function:: not_(obj)
55 __not__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000056
Thomas Wouters1b7f8912007-09-19 03:06:30 +000057 Return the outcome of :keyword:`not` *obj*. (Note that there is no
Georg Brandl116aa622007-08-15 14:28:22 +000058 :meth:`__not__` method for object instances; only the interpreter core defines
59 this operation. The result is affected by the :meth:`__bool__` and
60 :meth:`__len__` methods.)
61
62
Thomas Wouters1b7f8912007-09-19 03:06:30 +000063.. function:: truth(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000064
Thomas Wouters1b7f8912007-09-19 03:06:30 +000065 Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
Georg Brandl116aa622007-08-15 14:28:22 +000066 equivalent to using the :class:`bool` constructor.
67
68
69.. function:: is_(a, b)
70
71 Return ``a is b``. Tests object identity.
72
Georg Brandl116aa622007-08-15 14:28:22 +000073
74.. function:: is_not(a, b)
75
76 Return ``a is not b``. Tests object identity.
77
Georg Brandl116aa622007-08-15 14:28:22 +000078
79The mathematical and bitwise operations are the most numerous:
80
81
Thomas Wouters1b7f8912007-09-19 03:06:30 +000082.. function:: abs(obj)
83 __abs__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000084
Thomas Wouters1b7f8912007-09-19 03:06:30 +000085 Return the absolute value of *obj*.
Georg Brandl116aa622007-08-15 14:28:22 +000086
87
88.. function:: add(a, b)
89 __add__(a, b)
90
91 Return ``a + b``, for *a* and *b* numbers.
92
93
94.. function:: and_(a, b)
95 __and__(a, b)
96
97 Return the bitwise and of *a* and *b*.
98
99
Georg Brandl116aa622007-08-15 14:28:22 +0000100.. function:: floordiv(a, b)
101 __floordiv__(a, b)
102
103 Return ``a // b``.
104
Georg Brandl116aa622007-08-15 14:28:22 +0000105
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000106.. function:: index(a)
107 __index__(a)
108
109 Return *a* converted to an integer. Equivalent to ``a.__index__()``.
110
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000111
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000112.. function:: inv(obj)
113 invert(obj)
114 __inv__(obj)
115 __invert__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000116
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000117 Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
Georg Brandl116aa622007-08-15 14:28:22 +0000118
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120.. function:: lshift(a, b)
121 __lshift__(a, b)
122
123 Return *a* shifted left by *b*.
124
125
126.. function:: mod(a, b)
127 __mod__(a, b)
128
129 Return ``a % b``.
130
131
132.. function:: mul(a, b)
133 __mul__(a, b)
134
135 Return ``a * b``, for *a* and *b* numbers.
136
137
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000138.. function:: neg(obj)
139 __neg__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000140
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000141 Return *obj* negated (``-obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000142
143
144.. function:: or_(a, b)
145 __or__(a, b)
146
147 Return the bitwise or of *a* and *b*.
148
149
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000150.. function:: pos(obj)
151 __pos__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000152
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000153 Return *obj* positive (``+obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000154
155
156.. function:: pow(a, b)
157 __pow__(a, b)
158
159 Return ``a ** b``, for *a* and *b* numbers.
160
Georg Brandl116aa622007-08-15 14:28:22 +0000161
162.. function:: rshift(a, b)
163 __rshift__(a, b)
164
165 Return *a* shifted right by *b*.
166
167
168.. function:: sub(a, b)
169 __sub__(a, b)
170
171 Return ``a - b``.
172
173
174.. function:: truediv(a, b)
175 __truediv__(a, b)
176
Georg Brandlf6945182008-02-01 11:56:49 +0000177 Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
178 "true" division.
Georg Brandl116aa622007-08-15 14:28:22 +0000179
Georg Brandl116aa622007-08-15 14:28:22 +0000180
181.. function:: xor(a, b)
182 __xor__(a, b)
183
184 Return the bitwise exclusive or of *a* and *b*.
185
186
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000187Operations which work with sequences (some of them with mappings too) include:
Georg Brandl116aa622007-08-15 14:28:22 +0000188
189.. function:: concat(a, b)
190 __concat__(a, b)
191
192 Return ``a + b`` for *a* and *b* sequences.
193
194
195.. function:: contains(a, b)
196 __contains__(a, b)
197
198 Return the outcome of the test ``b in a``. Note the reversed operands.
199
Georg Brandl116aa622007-08-15 14:28:22 +0000200
201.. function:: countOf(a, b)
202
203 Return the number of occurrences of *b* in *a*.
204
205
206.. function:: delitem(a, b)
207 __delitem__(a, b)
208
209 Remove the value of *a* at index *b*.
210
Georg Brandl48310cd2009-01-03 21:18:54 +0000211
Georg Brandl116aa622007-08-15 14:28:22 +0000212.. function:: getitem(a, b)
213 __getitem__(a, b)
214
215 Return the value of *a* at index *b*.
216
217
Georg Brandl116aa622007-08-15 14:28:22 +0000218.. function:: indexOf(a, b)
219
220 Return the index of the first of occurrence of *b* in *a*.
221
222
Georg Brandl116aa622007-08-15 14:28:22 +0000223.. function:: setitem(a, b, c)
224 __setitem__(a, b, c)
225
226 Set the value of *a* at index *b* to *c*.
227
Georg Brandl116aa622007-08-15 14:28:22 +0000228Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
Christian Heimesfe337bf2008-03-23 21:54:12 +0000229their character equivalents.
Georg Brandl116aa622007-08-15 14:28:22 +0000230
Georg Brandl116aa622007-08-15 14:28:22 +0000231 >>> d = {}
232 >>> keys = range(256)
233 >>> vals = map(chr, keys)
Christian Heimesfe337bf2008-03-23 21:54:12 +0000234 >>> map(operator.setitem, [d]*len(keys), keys, vals) # doctest: +SKIP
Georg Brandl116aa622007-08-15 14:28:22 +0000235
236.. XXX: find a better, readable, example
237
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200238.. function:: length_hint(obj, default=0)
239
240 Return an estimated length for the object *o*. First trying to return its
Ezio Melottie12dc282012-10-07 12:09:36 +0300241 actual length, then an estimate using :meth:`object.__length_hint__`, and
242 finally returning the default value.
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200243
Armin Ronacher74b38b12012-10-07 10:29:32 +0200244 .. versionadded:: 3.4
245
Georg Brandl116aa622007-08-15 14:28:22 +0000246The :mod:`operator` module also defines tools for generalized attribute and item
247lookups. These are useful for making fast field extractors as arguments for
248:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
249expect a function argument.
250
251
Ezio Melottibabc8222013-05-08 10:53:11 +0300252.. function:: attrgetter(attr)
253 attrgetter(*attrs)
Georg Brandl116aa622007-08-15 14:28:22 +0000254
Ezio Melottibabc8222013-05-08 10:53:11 +0300255 Return a callable object that fetches *attr* from its operand.
256 If more than one attribute is requested, returns a tuple of attributes.
257 The attribute names can also contain dots. For example:
258
259 * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.
260
261 * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns
262 ``(b.name, b.date)``.
263
264 * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)``
265 returns ``(r.name.first, r.name.last)``.
266
267 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000268
269 def attrgetter(*items):
Antoine Pitroue9745712010-10-31 15:26:04 +0000270 if any(not isinstance(item, str) for item in items):
271 raise TypeError('attribute name must be a string')
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000272 if len(items) == 1:
273 attr = items[0]
274 def g(obj):
275 return resolve_attr(obj, attr)
276 else:
277 def g(obj):
278 return tuple(resolve_att(obj, attr) for attr in items)
279 return g
280
281 def resolve_attr(obj, attr):
282 for name in attr.split("."):
283 obj = getattr(obj, name)
284 return obj
285
Georg Brandl116aa622007-08-15 14:28:22 +0000286
Ezio Melottibabc8222013-05-08 10:53:11 +0300287.. function:: itemgetter(item)
288 itemgetter(*items)
Georg Brandl116aa622007-08-15 14:28:22 +0000289
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000290 Return a callable object that fetches *item* from its operand using the
291 operand's :meth:`__getitem__` method. If multiple items are specified,
Ezio Melottibabc8222013-05-08 10:53:11 +0300292 returns a tuple of lookup values. For example:
293
294 * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
295
296 * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns
297 ``(r[2], r[5], r[3])``.
298
299 Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000300
Benjamin Petersonffec8102010-08-21 20:01:28 +0000301 def itemgetter(*items):
302 if len(items) == 1:
303 item = items[0]
304 def g(obj):
305 return obj[item]
306 else:
307 def g(obj):
308 return tuple(obj[item] for item in items)
309 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000310
311 The items can be any type accepted by the operand's :meth:`__getitem__`
312 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000313 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000314
Christian Heimesfe337bf2008-03-23 21:54:12 +0000315 >>> itemgetter(1)('ABCDEFG')
316 'B'
317 >>> itemgetter(1,3,5)('ABCDEFG')
318 ('B', 'D', 'F')
319 >>> itemgetter(slice(2,None))('ABCDEFG')
320 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000321
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000322
323 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000324 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000325
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000326 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
327 >>> getcount = itemgetter(1)
Raymond Hettingerd292a172010-09-01 07:46:54 +0000328 >>> list(map(getcount, inventory))
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000329 [3, 2, 5, 1]
330 >>> sorted(inventory, key=getcount)
331 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000332
333
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000334.. function:: methodcaller(name[, args...])
335
336 Return a callable object that calls the method *name* on its operand. If
337 additional arguments and/or keyword arguments are given, they will be given
Ezio Melottibabc8222013-05-08 10:53:11 +0300338 to the method as well. For example:
339
340 * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``.
341
342 * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)``
343 returns ``b.name('foo', bar=1)``.
344
345 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000346
347 def methodcaller(name, *args, **kwargs):
348 def caller(obj):
349 return getattr(obj, name)(*args, **kwargs)
350 return caller
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000351
352
Georg Brandl116aa622007-08-15 14:28:22 +0000353.. _operator-map:
354
355Mapping Operators to Functions
356------------------------------
357
358This table shows how abstract operations correspond to operator symbols in the
359Python syntax and the functions in the :mod:`operator` module.
360
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000361+-----------------------+-------------------------+---------------------------------------+
362| Operation | Syntax | Function |
363+=======================+=========================+=======================================+
364| Addition | ``a + b`` | ``add(a, b)`` |
365+-----------------------+-------------------------+---------------------------------------+
366| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
367+-----------------------+-------------------------+---------------------------------------+
368| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
369+-----------------------+-------------------------+---------------------------------------+
Sandro Tosi83c48822012-02-28 22:28:28 +0100370| Division | ``a / b`` | ``truediv(a, b)`` |
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000371+-----------------------+-------------------------+---------------------------------------+
372| Division | ``a // b`` | ``floordiv(a, b)`` |
373+-----------------------+-------------------------+---------------------------------------+
374| Bitwise And | ``a & b`` | ``and_(a, b)`` |
375+-----------------------+-------------------------+---------------------------------------+
376| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
377+-----------------------+-------------------------+---------------------------------------+
378| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
379+-----------------------+-------------------------+---------------------------------------+
380| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
381+-----------------------+-------------------------+---------------------------------------+
382| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
383+-----------------------+-------------------------+---------------------------------------+
384| Identity | ``a is b`` | ``is_(a, b)`` |
385+-----------------------+-------------------------+---------------------------------------+
386| Identity | ``a is not b`` | ``is_not(a, b)`` |
387+-----------------------+-------------------------+---------------------------------------+
388| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
389+-----------------------+-------------------------+---------------------------------------+
390| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
391+-----------------------+-------------------------+---------------------------------------+
392| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
393+-----------------------+-------------------------+---------------------------------------+
394| Left Shift | ``a << b`` | ``lshift(a, b)`` |
395+-----------------------+-------------------------+---------------------------------------+
396| Modulo | ``a % b`` | ``mod(a, b)`` |
397+-----------------------+-------------------------+---------------------------------------+
398| Multiplication | ``a * b`` | ``mul(a, b)`` |
399+-----------------------+-------------------------+---------------------------------------+
400| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
401+-----------------------+-------------------------+---------------------------------------+
402| Negation (Logical) | ``not a`` | ``not_(a)`` |
403+-----------------------+-------------------------+---------------------------------------+
404| Positive | ``+ a`` | ``pos(a)`` |
405+-----------------------+-------------------------+---------------------------------------+
406| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
407+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000408| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
409+-----------------------+-------------------------+---------------------------------------+
410| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
411+-----------------------+-------------------------+---------------------------------------+
412| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
413+-----------------------+-------------------------+---------------------------------------+
414| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
415+-----------------------+-------------------------+---------------------------------------+
416| Subtraction | ``a - b`` | ``sub(a, b)`` |
417+-----------------------+-------------------------+---------------------------------------+
418| Truth Test | ``obj`` | ``truth(obj)`` |
419+-----------------------+-------------------------+---------------------------------------+
420| Ordering | ``a < b`` | ``lt(a, b)`` |
421+-----------------------+-------------------------+---------------------------------------+
422| Ordering | ``a <= b`` | ``le(a, b)`` |
423+-----------------------+-------------------------+---------------------------------------+
424| Equality | ``a == b`` | ``eq(a, b)`` |
425+-----------------------+-------------------------+---------------------------------------+
426| Difference | ``a != b`` | ``ne(a, b)`` |
427+-----------------------+-------------------------+---------------------------------------+
428| Ordering | ``a >= b`` | ``ge(a, b)`` |
429+-----------------------+-------------------------+---------------------------------------+
430| Ordering | ``a > b`` | ``gt(a, b)`` |
431+-----------------------+-------------------------+---------------------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000432
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000433Inplace Operators
Sandro Tosi3f7d1d32012-06-01 20:23:20 +0200434-----------------
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000435
436Many operations have an "in-place" version. Listed below are functions
437providing a more primitive access to in-place operators than the usual syntax
438does; for example, the :term:`statement` ``x += y`` is equivalent to
439``x = operator.iadd(x, y)``. Another way to put it is to say that
440``z = operator.iadd(x, y)`` is equivalent to the compound statement
441``z = x; z += y``.
442
443In those examples, note that when an in-place method is called, the computation
444and assignment are performed in two separate steps. The in-place functions
445listed below only do the first step, calling the in-place method. The second
446step, assignment, is not handled.
447
448For immutable targets such as strings, numbers, and tuples, the updated
449value is computed, but not assigned back to the input variable:
450
451>>> a = 'hello'
452>>> iadd(a, ' world')
453'hello world'
454>>> a
455'hello'
456
457For mutable targets such as lists and dictionaries, the inplace method
458will perform the update, so no subsequent assignment is necessary:
459
460>>> s = ['h', 'e', 'l', 'l', 'o']
461>>> iadd(s, [' ', 'w', 'o', 'r', 'l', 'd'])
462['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
463>>> s
464['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
465
466.. function:: iadd(a, b)
467 __iadd__(a, b)
468
469 ``a = iadd(a, b)`` is equivalent to ``a += b``.
470
471
472.. function:: iand(a, b)
473 __iand__(a, b)
474
475 ``a = iand(a, b)`` is equivalent to ``a &= b``.
476
477
478.. function:: iconcat(a, b)
479 __iconcat__(a, b)
480
481 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
482
483
484.. function:: ifloordiv(a, b)
485 __ifloordiv__(a, b)
486
487 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
488
489
490.. function:: ilshift(a, b)
491 __ilshift__(a, b)
492
493 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
494
495
496.. function:: imod(a, b)
497 __imod__(a, b)
498
499 ``a = imod(a, b)`` is equivalent to ``a %= b``.
500
501
502.. function:: imul(a, b)
503 __imul__(a, b)
504
505 ``a = imul(a, b)`` is equivalent to ``a *= b``.
506
507
508.. function:: ior(a, b)
509 __ior__(a, b)
510
511 ``a = ior(a, b)`` is equivalent to ``a |= b``.
512
513
514.. function:: ipow(a, b)
515 __ipow__(a, b)
516
517 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
518
519
520.. function:: irshift(a, b)
521 __irshift__(a, b)
522
523 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
524
525
526.. function:: isub(a, b)
527 __isub__(a, b)
528
529 ``a = isub(a, b)`` is equivalent to ``a -= b``.
530
531
532.. function:: itruediv(a, b)
533 __itruediv__(a, b)
534
535 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
536
537
538.. function:: ixor(a, b)
539 __ixor__(a, b)
540
541 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.