blob: c01e63b77a993382f6e820956321d4f49f997812 [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
Benjamin Petersond51374e2014-04-09 23:55:56 -0400141.. function:: matmul(a, b)
142 __matmul__(a, b)
143
144 Return ``a @ b``.
145
146 .. versionadded:: 3.5
147
148
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000149.. function:: neg(obj)
150 __neg__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000151
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000152 Return *obj* negated (``-obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000153
154
155.. function:: or_(a, b)
156 __or__(a, b)
157
158 Return the bitwise or of *a* and *b*.
159
160
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000161.. function:: pos(obj)
162 __pos__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000163
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000164 Return *obj* positive (``+obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000165
166
167.. function:: pow(a, b)
168 __pow__(a, b)
169
170 Return ``a ** b``, for *a* and *b* numbers.
171
Georg Brandl116aa622007-08-15 14:28:22 +0000172
173.. function:: rshift(a, b)
174 __rshift__(a, b)
175
176 Return *a* shifted right by *b*.
177
178
179.. function:: sub(a, b)
180 __sub__(a, b)
181
182 Return ``a - b``.
183
184
185.. function:: truediv(a, b)
186 __truediv__(a, b)
187
Georg Brandlf6945182008-02-01 11:56:49 +0000188 Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
189 "true" division.
Georg Brandl116aa622007-08-15 14:28:22 +0000190
Georg Brandl116aa622007-08-15 14:28:22 +0000191
192.. function:: xor(a, b)
193 __xor__(a, b)
194
195 Return the bitwise exclusive or of *a* and *b*.
196
197
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000198Operations which work with sequences (some of them with mappings too) include:
Georg Brandl116aa622007-08-15 14:28:22 +0000199
200.. function:: concat(a, b)
201 __concat__(a, b)
202
203 Return ``a + b`` for *a* and *b* sequences.
204
205
206.. function:: contains(a, b)
207 __contains__(a, b)
208
209 Return the outcome of the test ``b in a``. Note the reversed operands.
210
Georg Brandl116aa622007-08-15 14:28:22 +0000211
212.. function:: countOf(a, b)
213
214 Return the number of occurrences of *b* in *a*.
215
216
217.. function:: delitem(a, b)
218 __delitem__(a, b)
219
220 Remove the value of *a* at index *b*.
221
Georg Brandl48310cd2009-01-03 21:18:54 +0000222
Georg Brandl116aa622007-08-15 14:28:22 +0000223.. function:: getitem(a, b)
224 __getitem__(a, b)
225
226 Return the value of *a* at index *b*.
227
228
Georg Brandl116aa622007-08-15 14:28:22 +0000229.. function:: indexOf(a, b)
230
231 Return the index of the first of occurrence of *b* in *a*.
232
233
Georg Brandl116aa622007-08-15 14:28:22 +0000234.. function:: setitem(a, b, c)
235 __setitem__(a, b, c)
236
237 Set the value of *a* at index *b* to *c*.
238
Georg Brandl116aa622007-08-15 14:28:22 +0000239
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200240.. function:: length_hint(obj, default=0)
241
R David Murraye8db1622014-03-10 15:00:33 -0400242 Return an estimated length for the object *o*. First try to return its
Ezio Melottie12dc282012-10-07 12:09:36 +0300243 actual length, then an estimate using :meth:`object.__length_hint__`, and
R David Murraye8db1622014-03-10 15:00:33 -0400244 finally return the default value.
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200245
Armin Ronacher74b38b12012-10-07 10:29:32 +0200246 .. versionadded:: 3.4
247
Georg Brandl116aa622007-08-15 14:28:22 +0000248The :mod:`operator` module also defines tools for generalized attribute and item
249lookups. These are useful for making fast field extractors as arguments for
250:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
251expect a function argument.
252
253
Ezio Melottibabc8222013-05-08 10:53:11 +0300254.. function:: attrgetter(attr)
255 attrgetter(*attrs)
Georg Brandl116aa622007-08-15 14:28:22 +0000256
Ezio Melottibabc8222013-05-08 10:53:11 +0300257 Return a callable object that fetches *attr* from its operand.
258 If more than one attribute is requested, returns a tuple of attributes.
259 The attribute names can also contain dots. For example:
260
261 * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.
262
263 * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns
264 ``(b.name, b.date)``.
265
266 * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)``
Zachary Ware0bffca02013-12-18 12:21:49 -0600267 returns ``(b.name.first, b.name.last)``.
Ezio Melottibabc8222013-05-08 10:53:11 +0300268
269 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000270
271 def attrgetter(*items):
Antoine Pitroue9745712010-10-31 15:26:04 +0000272 if any(not isinstance(item, str) for item in items):
273 raise TypeError('attribute name must be a string')
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000274 if len(items) == 1:
275 attr = items[0]
276 def g(obj):
277 return resolve_attr(obj, attr)
278 else:
279 def g(obj):
Georg Brandlf6d63472013-10-06 19:14:35 +0200280 return tuple(resolve_attr(obj, attr) for attr in items)
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000281 return g
282
283 def resolve_attr(obj, attr):
284 for name in attr.split("."):
285 obj = getattr(obj, name)
286 return obj
287
Georg Brandl116aa622007-08-15 14:28:22 +0000288
Ezio Melottibabc8222013-05-08 10:53:11 +0300289.. function:: itemgetter(item)
290 itemgetter(*items)
Georg Brandl116aa622007-08-15 14:28:22 +0000291
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000292 Return a callable object that fetches *item* from its operand using the
293 operand's :meth:`__getitem__` method. If multiple items are specified,
Ezio Melottibabc8222013-05-08 10:53:11 +0300294 returns a tuple of lookup values. For example:
295
296 * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
297
298 * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns
299 ``(r[2], r[5], r[3])``.
300
301 Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000302
Benjamin Petersonffec8102010-08-21 20:01:28 +0000303 def itemgetter(*items):
304 if len(items) == 1:
305 item = items[0]
306 def g(obj):
307 return obj[item]
308 else:
309 def g(obj):
310 return tuple(obj[item] for item in items)
311 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000312
313 The items can be any type accepted by the operand's :meth:`__getitem__`
314 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000315 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000316
Christian Heimesfe337bf2008-03-23 21:54:12 +0000317 >>> itemgetter(1)('ABCDEFG')
318 'B'
319 >>> itemgetter(1,3,5)('ABCDEFG')
320 ('B', 'D', 'F')
321 >>> itemgetter(slice(2,None))('ABCDEFG')
322 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000323
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000324
325 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000326 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000327
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000328 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
329 >>> getcount = itemgetter(1)
Raymond Hettingerd292a172010-09-01 07:46:54 +0000330 >>> list(map(getcount, inventory))
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000331 [3, 2, 5, 1]
332 >>> sorted(inventory, key=getcount)
333 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000334
335
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000336.. function:: methodcaller(name[, args...])
337
338 Return a callable object that calls the method *name* on its operand. If
339 additional arguments and/or keyword arguments are given, they will be given
Ezio Melottibabc8222013-05-08 10:53:11 +0300340 to the method as well. For example:
341
342 * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``.
343
344 * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)``
345 returns ``b.name('foo', bar=1)``.
346
347 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000348
349 def methodcaller(name, *args, **kwargs):
350 def caller(obj):
351 return getattr(obj, name)(*args, **kwargs)
352 return caller
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000353
354
Georg Brandl116aa622007-08-15 14:28:22 +0000355.. _operator-map:
356
357Mapping Operators to Functions
358------------------------------
359
360This table shows how abstract operations correspond to operator symbols in the
361Python syntax and the functions in the :mod:`operator` module.
362
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000363+-----------------------+-------------------------+---------------------------------------+
364| Operation | Syntax | Function |
365+=======================+=========================+=======================================+
366| Addition | ``a + b`` | ``add(a, b)`` |
367+-----------------------+-------------------------+---------------------------------------+
368| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
369+-----------------------+-------------------------+---------------------------------------+
370| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
371+-----------------------+-------------------------+---------------------------------------+
Sandro Tosi83c48822012-02-28 22:28:28 +0100372| Division | ``a / b`` | ``truediv(a, b)`` |
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000373+-----------------------+-------------------------+---------------------------------------+
374| Division | ``a // b`` | ``floordiv(a, b)`` |
375+-----------------------+-------------------------+---------------------------------------+
376| Bitwise And | ``a & b`` | ``and_(a, b)`` |
377+-----------------------+-------------------------+---------------------------------------+
378| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
379+-----------------------+-------------------------+---------------------------------------+
380| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
381+-----------------------+-------------------------+---------------------------------------+
382| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
383+-----------------------+-------------------------+---------------------------------------+
384| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
385+-----------------------+-------------------------+---------------------------------------+
386| Identity | ``a is b`` | ``is_(a, b)`` |
387+-----------------------+-------------------------+---------------------------------------+
388| Identity | ``a is not b`` | ``is_not(a, b)`` |
389+-----------------------+-------------------------+---------------------------------------+
390| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
391+-----------------------+-------------------------+---------------------------------------+
392| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
393+-----------------------+-------------------------+---------------------------------------+
394| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
395+-----------------------+-------------------------+---------------------------------------+
396| Left Shift | ``a << b`` | ``lshift(a, b)`` |
397+-----------------------+-------------------------+---------------------------------------+
398| Modulo | ``a % b`` | ``mod(a, b)`` |
399+-----------------------+-------------------------+---------------------------------------+
400| Multiplication | ``a * b`` | ``mul(a, b)`` |
401+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersond51374e2014-04-09 23:55:56 -0400402| Matrix Multiplication | ``a @ b`` | ``matmul(a, b)`` |
403+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000404| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
405+-----------------------+-------------------------+---------------------------------------+
406| Negation (Logical) | ``not a`` | ``not_(a)`` |
407+-----------------------+-------------------------+---------------------------------------+
408| Positive | ``+ a`` | ``pos(a)`` |
409+-----------------------+-------------------------+---------------------------------------+
410| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
411+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000412| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
413+-----------------------+-------------------------+---------------------------------------+
414| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
415+-----------------------+-------------------------+---------------------------------------+
416| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
417+-----------------------+-------------------------+---------------------------------------+
418| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
419+-----------------------+-------------------------+---------------------------------------+
420| Subtraction | ``a - b`` | ``sub(a, b)`` |
421+-----------------------+-------------------------+---------------------------------------+
422| Truth Test | ``obj`` | ``truth(obj)`` |
423+-----------------------+-------------------------+---------------------------------------+
424| Ordering | ``a < b`` | ``lt(a, b)`` |
425+-----------------------+-------------------------+---------------------------------------+
426| Ordering | ``a <= b`` | ``le(a, b)`` |
427+-----------------------+-------------------------+---------------------------------------+
428| Equality | ``a == b`` | ``eq(a, b)`` |
429+-----------------------+-------------------------+---------------------------------------+
430| Difference | ``a != b`` | ``ne(a, b)`` |
431+-----------------------+-------------------------+---------------------------------------+
432| Ordering | ``a >= b`` | ``ge(a, b)`` |
433+-----------------------+-------------------------+---------------------------------------+
434| Ordering | ``a > b`` | ``gt(a, b)`` |
435+-----------------------+-------------------------+---------------------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000436
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000437Inplace Operators
Sandro Tosi3f7d1d32012-06-01 20:23:20 +0200438-----------------
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000439
440Many operations have an "in-place" version. Listed below are functions
441providing a more primitive access to in-place operators than the usual syntax
442does; for example, the :term:`statement` ``x += y`` is equivalent to
443``x = operator.iadd(x, y)``. Another way to put it is to say that
444``z = operator.iadd(x, y)`` is equivalent to the compound statement
445``z = x; z += y``.
446
447In those examples, note that when an in-place method is called, the computation
448and assignment are performed in two separate steps. The in-place functions
449listed below only do the first step, calling the in-place method. The second
450step, assignment, is not handled.
451
452For immutable targets such as strings, numbers, and tuples, the updated
453value is computed, but not assigned back to the input variable:
454
455>>> a = 'hello'
456>>> iadd(a, ' world')
457'hello world'
458>>> a
459'hello'
460
461For mutable targets such as lists and dictionaries, the inplace method
462will perform the update, so no subsequent assignment is necessary:
463
464>>> s = ['h', 'e', 'l', 'l', 'o']
465>>> iadd(s, [' ', 'w', 'o', 'r', 'l', 'd'])
466['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
467>>> s
468['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
469
470.. function:: iadd(a, b)
471 __iadd__(a, b)
472
473 ``a = iadd(a, b)`` is equivalent to ``a += b``.
474
475
476.. function:: iand(a, b)
477 __iand__(a, b)
478
479 ``a = iand(a, b)`` is equivalent to ``a &= b``.
480
481
482.. function:: iconcat(a, b)
483 __iconcat__(a, b)
484
485 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
486
487
488.. function:: ifloordiv(a, b)
489 __ifloordiv__(a, b)
490
491 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
492
493
494.. function:: ilshift(a, b)
495 __ilshift__(a, b)
496
497 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
498
499
500.. function:: imod(a, b)
501 __imod__(a, b)
502
503 ``a = imod(a, b)`` is equivalent to ``a %= b``.
504
505
506.. function:: imul(a, b)
507 __imul__(a, b)
508
509 ``a = imul(a, b)`` is equivalent to ``a *= b``.
510
511
Benjamin Petersond51374e2014-04-09 23:55:56 -0400512.. function:: imatmul(a, b)
513 __imatmul__(a, b)
514
515 ``a = imatmul(a, b)`` is equivalent to ``a @= b``.
516
517 .. versionadded:: 3.5
518
519
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000520.. function:: ior(a, b)
521 __ior__(a, b)
522
523 ``a = ior(a, b)`` is equivalent to ``a |= b``.
524
525
526.. function:: ipow(a, b)
527 __ipow__(a, b)
528
529 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
530
531
532.. function:: irshift(a, b)
533 __irshift__(a, b)
534
535 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
536
537
538.. function:: isub(a, b)
539 __isub__(a, b)
540
541 ``a = isub(a, b)`` is equivalent to ``a -= b``.
542
543
544.. function:: itruediv(a, b)
545 __itruediv__(a, b)
546
547 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
548
549
550.. function:: ixor(a, b)
551 __ixor__(a, b)
552
553 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.