blob: f9e2a3d003e20490f20468e375c9e424cca0012c [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
Raymond Hettinger3f5228d2013-05-10 19:57:44 -070014**Source code:** :source:`Lib/operator.py`
15
16--------------
Georg Brandl116aa622007-08-15 14:28:22 +000017
Benjamin Peterson0f1e3ac2011-12-20 10:12:41 -060018The :mod:`operator` module exports a set of efficient functions corresponding to
19the intrinsic operators of Python. For example, ``operator.add(x, y)`` is
Benjamin Peterson1c92cfe2011-12-19 16:41:11 -050020equivalent to the expression ``x+y``. The function names are those used for
21special class methods; variants without leading and trailing ``__`` are also
22provided for convenience.
Georg Brandl116aa622007-08-15 14:28:22 +000023
24The functions fall into categories that perform object comparisons, logical
Georg Brandlb30f3302011-01-06 09:23:56 +000025operations, mathematical operations and sequence operations.
Georg Brandl116aa622007-08-15 14:28:22 +000026
27The object comparison functions are useful for all objects, and are named after
28the rich comparison operators they support:
29
30
31.. function:: lt(a, b)
32 le(a, b)
33 eq(a, b)
34 ne(a, b)
35 ge(a, b)
36 gt(a, b)
37 __lt__(a, b)
38 __le__(a, b)
39 __eq__(a, b)
40 __ne__(a, b)
41 __ge__(a, b)
42 __gt__(a, b)
43
44 Perform "rich comparisons" between *a* and *b*. Specifically, ``lt(a, b)`` is
45 equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
46 b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
47 ``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
Mark Dickinsonc48d8342009-02-01 14:18:10 +000048 >= b``. Note that these functions can return any value, which may
49 or may not be interpretable as a Boolean value. See
50 :ref:`comparisons` for more information about rich comparisons.
Georg Brandl116aa622007-08-15 14:28:22 +000051
Georg Brandl116aa622007-08-15 14:28:22 +000052
53The logical operations are also generally applicable to all objects, and support
54truth tests, identity tests, and boolean operations:
55
56
Thomas Wouters1b7f8912007-09-19 03:06:30 +000057.. function:: not_(obj)
58 __not__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000059
Thomas Wouters1b7f8912007-09-19 03:06:30 +000060 Return the outcome of :keyword:`not` *obj*. (Note that there is no
Georg Brandl116aa622007-08-15 14:28:22 +000061 :meth:`__not__` method for object instances; only the interpreter core defines
62 this operation. The result is affected by the :meth:`__bool__` and
63 :meth:`__len__` methods.)
64
65
Thomas Wouters1b7f8912007-09-19 03:06:30 +000066.. function:: truth(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000067
Thomas Wouters1b7f8912007-09-19 03:06:30 +000068 Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
Georg Brandl116aa622007-08-15 14:28:22 +000069 equivalent to using the :class:`bool` constructor.
70
71
72.. function:: is_(a, b)
73
74 Return ``a is b``. Tests object identity.
75
Georg Brandl116aa622007-08-15 14:28:22 +000076
77.. function:: is_not(a, b)
78
79 Return ``a is not b``. Tests object identity.
80
Georg Brandl116aa622007-08-15 14:28:22 +000081
82The mathematical and bitwise operations are the most numerous:
83
84
Thomas Wouters1b7f8912007-09-19 03:06:30 +000085.. function:: abs(obj)
86 __abs__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000087
Thomas Wouters1b7f8912007-09-19 03:06:30 +000088 Return the absolute value of *obj*.
Georg Brandl116aa622007-08-15 14:28:22 +000089
90
91.. function:: add(a, b)
92 __add__(a, b)
93
94 Return ``a + b``, for *a* and *b* numbers.
95
96
97.. function:: and_(a, b)
98 __and__(a, b)
99
100 Return the bitwise and of *a* and *b*.
101
102
Georg Brandl116aa622007-08-15 14:28:22 +0000103.. function:: floordiv(a, b)
104 __floordiv__(a, b)
105
106 Return ``a // b``.
107
Georg Brandl116aa622007-08-15 14:28:22 +0000108
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000109.. function:: index(a)
110 __index__(a)
111
112 Return *a* converted to an integer. Equivalent to ``a.__index__()``.
113
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000114
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000115.. function:: inv(obj)
116 invert(obj)
117 __inv__(obj)
118 __invert__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000119
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000120 Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
Georg Brandl116aa622007-08-15 14:28:22 +0000121
Georg Brandl116aa622007-08-15 14:28:22 +0000122
123.. function:: lshift(a, b)
124 __lshift__(a, b)
125
126 Return *a* shifted left by *b*.
127
128
129.. function:: mod(a, b)
130 __mod__(a, b)
131
132 Return ``a % b``.
133
134
135.. function:: mul(a, b)
136 __mul__(a, b)
137
138 Return ``a * b``, for *a* and *b* numbers.
139
140
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000141.. function:: neg(obj)
142 __neg__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000143
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000144 Return *obj* negated (``-obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000145
146
147.. function:: or_(a, b)
148 __or__(a, b)
149
150 Return the bitwise or of *a* and *b*.
151
152
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000153.. function:: pos(obj)
154 __pos__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000155
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000156 Return *obj* positive (``+obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000157
158
159.. function:: pow(a, b)
160 __pow__(a, b)
161
162 Return ``a ** b``, for *a* and *b* numbers.
163
Georg Brandl116aa622007-08-15 14:28:22 +0000164
165.. function:: rshift(a, b)
166 __rshift__(a, b)
167
168 Return *a* shifted right by *b*.
169
170
171.. function:: sub(a, b)
172 __sub__(a, b)
173
174 Return ``a - b``.
175
176
177.. function:: truediv(a, b)
178 __truediv__(a, b)
179
Georg Brandlf6945182008-02-01 11:56:49 +0000180 Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
181 "true" division.
Georg Brandl116aa622007-08-15 14:28:22 +0000182
Georg Brandl116aa622007-08-15 14:28:22 +0000183
184.. function:: xor(a, b)
185 __xor__(a, b)
186
187 Return the bitwise exclusive or of *a* and *b*.
188
189
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000190Operations which work with sequences (some of them with mappings too) include:
Georg Brandl116aa622007-08-15 14:28:22 +0000191
192.. function:: concat(a, b)
193 __concat__(a, b)
194
195 Return ``a + b`` for *a* and *b* sequences.
196
197
198.. function:: contains(a, b)
199 __contains__(a, b)
200
201 Return the outcome of the test ``b in a``. Note the reversed operands.
202
Georg Brandl116aa622007-08-15 14:28:22 +0000203
204.. function:: countOf(a, b)
205
206 Return the number of occurrences of *b* in *a*.
207
208
209.. function:: delitem(a, b)
210 __delitem__(a, b)
211
212 Remove the value of *a* at index *b*.
213
Georg Brandl48310cd2009-01-03 21:18:54 +0000214
Georg Brandl116aa622007-08-15 14:28:22 +0000215.. function:: getitem(a, b)
216 __getitem__(a, b)
217
218 Return the value of *a* at index *b*.
219
220
Georg Brandl116aa622007-08-15 14:28:22 +0000221.. function:: indexOf(a, b)
222
223 Return the index of the first of occurrence of *b* in *a*.
224
225
Georg Brandl116aa622007-08-15 14:28:22 +0000226.. function:: setitem(a, b, c)
227 __setitem__(a, b, c)
228
229 Set the value of *a* at index *b* to *c*.
230
Georg Brandl116aa622007-08-15 14:28:22 +0000231
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200232.. function:: length_hint(obj, default=0)
233
Larry Hastings3732ed22014-03-15 21:13:56 -0700234 Return an estimated length for the object *o*. First try to return its
Ezio Melottie12dc282012-10-07 12:09:36 +0300235 actual length, then an estimate using :meth:`object.__length_hint__`, and
Larry Hastings3732ed22014-03-15 21:13:56 -0700236 finally return the default value.
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200237
Armin Ronacher74b38b12012-10-07 10:29:32 +0200238 .. versionadded:: 3.4
239
Georg Brandl116aa622007-08-15 14:28:22 +0000240The :mod:`operator` module also defines tools for generalized attribute and item
241lookups. These are useful for making fast field extractors as arguments for
242:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
243expect a function argument.
244
245
Ezio Melottibabc8222013-05-08 10:53:11 +0300246.. function:: attrgetter(attr)
247 attrgetter(*attrs)
Georg Brandl116aa622007-08-15 14:28:22 +0000248
Ezio Melottibabc8222013-05-08 10:53:11 +0300249 Return a callable object that fetches *attr* from its operand.
250 If more than one attribute is requested, returns a tuple of attributes.
251 The attribute names can also contain dots. For example:
252
253 * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.
254
255 * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns
256 ``(b.name, b.date)``.
257
258 * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)``
Zachary Ware0bffca02013-12-18 12:21:49 -0600259 returns ``(b.name.first, b.name.last)``.
Ezio Melottibabc8222013-05-08 10:53:11 +0300260
261 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000262
263 def attrgetter(*items):
Antoine Pitroue9745712010-10-31 15:26:04 +0000264 if any(not isinstance(item, str) for item in items):
265 raise TypeError('attribute name must be a string')
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000266 if len(items) == 1:
267 attr = items[0]
268 def g(obj):
269 return resolve_attr(obj, attr)
270 else:
271 def g(obj):
Georg Brandlf6d63472013-10-06 19:14:35 +0200272 return tuple(resolve_attr(obj, attr) for attr in items)
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000273 return g
274
275 def resolve_attr(obj, attr):
276 for name in attr.split("."):
277 obj = getattr(obj, name)
278 return obj
279
Georg Brandl116aa622007-08-15 14:28:22 +0000280
Ezio Melottibabc8222013-05-08 10:53:11 +0300281.. function:: itemgetter(item)
282 itemgetter(*items)
Georg Brandl116aa622007-08-15 14:28:22 +0000283
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000284 Return a callable object that fetches *item* from its operand using the
285 operand's :meth:`__getitem__` method. If multiple items are specified,
Ezio Melottibabc8222013-05-08 10:53:11 +0300286 returns a tuple of lookup values. For example:
287
288 * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
289
290 * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns
291 ``(r[2], r[5], r[3])``.
292
293 Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000294
Benjamin Petersonffec8102010-08-21 20:01:28 +0000295 def itemgetter(*items):
296 if len(items) == 1:
297 item = items[0]
298 def g(obj):
299 return obj[item]
300 else:
301 def g(obj):
302 return tuple(obj[item] for item in items)
303 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000304
305 The items can be any type accepted by the operand's :meth:`__getitem__`
306 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000307 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000308
Christian Heimesfe337bf2008-03-23 21:54:12 +0000309 >>> itemgetter(1)('ABCDEFG')
310 'B'
311 >>> itemgetter(1,3,5)('ABCDEFG')
312 ('B', 'D', 'F')
313 >>> itemgetter(slice(2,None))('ABCDEFG')
314 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000315
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000316
317 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000318 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000319
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000320 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
321 >>> getcount = itemgetter(1)
Raymond Hettingerd292a172010-09-01 07:46:54 +0000322 >>> list(map(getcount, inventory))
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000323 [3, 2, 5, 1]
324 >>> sorted(inventory, key=getcount)
325 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000326
327
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000328.. function:: methodcaller(name[, args...])
329
330 Return a callable object that calls the method *name* on its operand. If
331 additional arguments and/or keyword arguments are given, they will be given
Ezio Melottibabc8222013-05-08 10:53:11 +0300332 to the method as well. For example:
333
334 * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``.
335
336 * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)``
337 returns ``b.name('foo', bar=1)``.
338
339 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000340
341 def methodcaller(name, *args, **kwargs):
342 def caller(obj):
343 return getattr(obj, name)(*args, **kwargs)
344 return caller
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000345
346
Georg Brandl116aa622007-08-15 14:28:22 +0000347.. _operator-map:
348
349Mapping Operators to Functions
350------------------------------
351
352This table shows how abstract operations correspond to operator symbols in the
353Python syntax and the functions in the :mod:`operator` module.
354
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000355+-----------------------+-------------------------+---------------------------------------+
356| Operation | Syntax | Function |
357+=======================+=========================+=======================================+
358| Addition | ``a + b`` | ``add(a, b)`` |
359+-----------------------+-------------------------+---------------------------------------+
360| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
361+-----------------------+-------------------------+---------------------------------------+
362| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
363+-----------------------+-------------------------+---------------------------------------+
Sandro Tosi83c48822012-02-28 22:28:28 +0100364| Division | ``a / b`` | ``truediv(a, b)`` |
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000365+-----------------------+-------------------------+---------------------------------------+
366| Division | ``a // b`` | ``floordiv(a, b)`` |
367+-----------------------+-------------------------+---------------------------------------+
368| Bitwise And | ``a & b`` | ``and_(a, b)`` |
369+-----------------------+-------------------------+---------------------------------------+
370| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
371+-----------------------+-------------------------+---------------------------------------+
372| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
373+-----------------------+-------------------------+---------------------------------------+
374| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
375+-----------------------+-------------------------+---------------------------------------+
376| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
377+-----------------------+-------------------------+---------------------------------------+
378| Identity | ``a is b`` | ``is_(a, b)`` |
379+-----------------------+-------------------------+---------------------------------------+
380| Identity | ``a is not b`` | ``is_not(a, b)`` |
381+-----------------------+-------------------------+---------------------------------------+
382| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
383+-----------------------+-------------------------+---------------------------------------+
384| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
385+-----------------------+-------------------------+---------------------------------------+
386| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
387+-----------------------+-------------------------+---------------------------------------+
388| Left Shift | ``a << b`` | ``lshift(a, b)`` |
389+-----------------------+-------------------------+---------------------------------------+
390| Modulo | ``a % b`` | ``mod(a, b)`` |
391+-----------------------+-------------------------+---------------------------------------+
392| Multiplication | ``a * b`` | ``mul(a, b)`` |
393+-----------------------+-------------------------+---------------------------------------+
394| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
395+-----------------------+-------------------------+---------------------------------------+
396| Negation (Logical) | ``not a`` | ``not_(a)`` |
397+-----------------------+-------------------------+---------------------------------------+
398| Positive | ``+ a`` | ``pos(a)`` |
399+-----------------------+-------------------------+---------------------------------------+
400| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
401+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000402| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
403+-----------------------+-------------------------+---------------------------------------+
404| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
405+-----------------------+-------------------------+---------------------------------------+
406| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
407+-----------------------+-------------------------+---------------------------------------+
408| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
409+-----------------------+-------------------------+---------------------------------------+
410| Subtraction | ``a - b`` | ``sub(a, b)`` |
411+-----------------------+-------------------------+---------------------------------------+
412| Truth Test | ``obj`` | ``truth(obj)`` |
413+-----------------------+-------------------------+---------------------------------------+
414| Ordering | ``a < b`` | ``lt(a, b)`` |
415+-----------------------+-------------------------+---------------------------------------+
416| Ordering | ``a <= b`` | ``le(a, b)`` |
417+-----------------------+-------------------------+---------------------------------------+
418| Equality | ``a == b`` | ``eq(a, b)`` |
419+-----------------------+-------------------------+---------------------------------------+
420| Difference | ``a != b`` | ``ne(a, b)`` |
421+-----------------------+-------------------------+---------------------------------------+
422| Ordering | ``a >= b`` | ``ge(a, b)`` |
423+-----------------------+-------------------------+---------------------------------------+
424| Ordering | ``a > b`` | ``gt(a, b)`` |
425+-----------------------+-------------------------+---------------------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000426
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000427Inplace Operators
Sandro Tosi3f7d1d32012-06-01 20:23:20 +0200428-----------------
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000429
430Many operations have an "in-place" version. Listed below are functions
431providing a more primitive access to in-place operators than the usual syntax
432does; for example, the :term:`statement` ``x += y`` is equivalent to
433``x = operator.iadd(x, y)``. Another way to put it is to say that
434``z = operator.iadd(x, y)`` is equivalent to the compound statement
435``z = x; z += y``.
436
437In those examples, note that when an in-place method is called, the computation
438and assignment are performed in two separate steps. The in-place functions
439listed below only do the first step, calling the in-place method. The second
440step, assignment, is not handled.
441
442For immutable targets such as strings, numbers, and tuples, the updated
443value is computed, but not assigned back to the input variable:
444
445>>> a = 'hello'
446>>> iadd(a, ' world')
447'hello world'
448>>> a
449'hello'
450
451For mutable targets such as lists and dictionaries, the inplace method
452will perform the update, so no subsequent assignment is necessary:
453
454>>> s = ['h', 'e', 'l', 'l', 'o']
455>>> iadd(s, [' ', 'w', 'o', 'r', 'l', 'd'])
456['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
457>>> s
458['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
459
460.. function:: iadd(a, b)
461 __iadd__(a, b)
462
463 ``a = iadd(a, b)`` is equivalent to ``a += b``.
464
465
466.. function:: iand(a, b)
467 __iand__(a, b)
468
469 ``a = iand(a, b)`` is equivalent to ``a &= b``.
470
471
472.. function:: iconcat(a, b)
473 __iconcat__(a, b)
474
475 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
476
477
478.. function:: ifloordiv(a, b)
479 __ifloordiv__(a, b)
480
481 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
482
483
484.. function:: ilshift(a, b)
485 __ilshift__(a, b)
486
487 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
488
489
490.. function:: imod(a, b)
491 __imod__(a, b)
492
493 ``a = imod(a, b)`` is equivalent to ``a %= b``.
494
495
496.. function:: imul(a, b)
497 __imul__(a, b)
498
499 ``a = imul(a, b)`` is equivalent to ``a *= b``.
500
501
502.. function:: ior(a, b)
503 __ior__(a, b)
504
505 ``a = ior(a, b)`` is equivalent to ``a |= b``.
506
507
508.. function:: ipow(a, b)
509 __ipow__(a, b)
510
511 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
512
513
514.. function:: irshift(a, b)
515 __irshift__(a, b)
516
517 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
518
519
520.. function:: isub(a, b)
521 __isub__(a, b)
522
523 ``a = isub(a, b)`` is equivalent to ``a -= b``.
524
525
526.. function:: itruediv(a, b)
527 __itruediv__(a, b)
528
529 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
530
531
532.. function:: ixor(a, b)
533 __ixor__(a, b)
534
535 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.