blob: 3654d133a8dcc05796873ae2ccfb6b8d7531814e [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 +0000239Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
Christian Heimesfe337bf2008-03-23 21:54:12 +0000240their character equivalents.
Georg Brandl116aa622007-08-15 14:28:22 +0000241
Georg Brandl116aa622007-08-15 14:28:22 +0000242 >>> d = {}
243 >>> keys = range(256)
244 >>> vals = map(chr, keys)
Christian Heimesfe337bf2008-03-23 21:54:12 +0000245 >>> map(operator.setitem, [d]*len(keys), keys, vals) # doctest: +SKIP
Georg Brandl116aa622007-08-15 14:28:22 +0000246
247.. XXX: find a better, readable, example
248
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200249.. function:: length_hint(obj, default=0)
250
R David Murraye8db1622014-03-10 15:00:33 -0400251 Return an estimated length for the object *o*. First try to return its
Ezio Melottie12dc282012-10-07 12:09:36 +0300252 actual length, then an estimate using :meth:`object.__length_hint__`, and
R David Murraye8db1622014-03-10 15:00:33 -0400253 finally return the default value.
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200254
Armin Ronacher74b38b12012-10-07 10:29:32 +0200255 .. versionadded:: 3.4
256
Georg Brandl116aa622007-08-15 14:28:22 +0000257The :mod:`operator` module also defines tools for generalized attribute and item
258lookups. These are useful for making fast field extractors as arguments for
259:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
260expect a function argument.
261
262
Ezio Melottibabc8222013-05-08 10:53:11 +0300263.. function:: attrgetter(attr)
264 attrgetter(*attrs)
Georg Brandl116aa622007-08-15 14:28:22 +0000265
Ezio Melottibabc8222013-05-08 10:53:11 +0300266 Return a callable object that fetches *attr* from its operand.
267 If more than one attribute is requested, returns a tuple of attributes.
268 The attribute names can also contain dots. For example:
269
270 * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.
271
272 * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns
273 ``(b.name, b.date)``.
274
275 * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)``
Zachary Ware0bffca02013-12-18 12:21:49 -0600276 returns ``(b.name.first, b.name.last)``.
Ezio Melottibabc8222013-05-08 10:53:11 +0300277
278 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000279
280 def attrgetter(*items):
Antoine Pitroue9745712010-10-31 15:26:04 +0000281 if any(not isinstance(item, str) for item in items):
282 raise TypeError('attribute name must be a string')
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000283 if len(items) == 1:
284 attr = items[0]
285 def g(obj):
286 return resolve_attr(obj, attr)
287 else:
288 def g(obj):
Georg Brandlf6d63472013-10-06 19:14:35 +0200289 return tuple(resolve_attr(obj, attr) for attr in items)
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000290 return g
291
292 def resolve_attr(obj, attr):
293 for name in attr.split("."):
294 obj = getattr(obj, name)
295 return obj
296
Georg Brandl116aa622007-08-15 14:28:22 +0000297
Ezio Melottibabc8222013-05-08 10:53:11 +0300298.. function:: itemgetter(item)
299 itemgetter(*items)
Georg Brandl116aa622007-08-15 14:28:22 +0000300
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000301 Return a callable object that fetches *item* from its operand using the
302 operand's :meth:`__getitem__` method. If multiple items are specified,
Ezio Melottibabc8222013-05-08 10:53:11 +0300303 returns a tuple of lookup values. For example:
304
305 * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
306
307 * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns
308 ``(r[2], r[5], r[3])``.
309
310 Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000311
Benjamin Petersonffec8102010-08-21 20:01:28 +0000312 def itemgetter(*items):
313 if len(items) == 1:
314 item = items[0]
315 def g(obj):
316 return obj[item]
317 else:
318 def g(obj):
319 return tuple(obj[item] for item in items)
320 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000321
322 The items can be any type accepted by the operand's :meth:`__getitem__`
323 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000324 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000325
Christian Heimesfe337bf2008-03-23 21:54:12 +0000326 >>> itemgetter(1)('ABCDEFG')
327 'B'
328 >>> itemgetter(1,3,5)('ABCDEFG')
329 ('B', 'D', 'F')
330 >>> itemgetter(slice(2,None))('ABCDEFG')
331 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000332
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000333
334 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000335 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000336
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000337 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
338 >>> getcount = itemgetter(1)
Raymond Hettingerd292a172010-09-01 07:46:54 +0000339 >>> list(map(getcount, inventory))
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000340 [3, 2, 5, 1]
341 >>> sorted(inventory, key=getcount)
342 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000343
344
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000345.. function:: methodcaller(name[, args...])
346
347 Return a callable object that calls the method *name* on its operand. If
348 additional arguments and/or keyword arguments are given, they will be given
Ezio Melottibabc8222013-05-08 10:53:11 +0300349 to the method as well. For example:
350
351 * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``.
352
353 * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)``
354 returns ``b.name('foo', bar=1)``.
355
356 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000357
358 def methodcaller(name, *args, **kwargs):
359 def caller(obj):
360 return getattr(obj, name)(*args, **kwargs)
361 return caller
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000362
363
Georg Brandl116aa622007-08-15 14:28:22 +0000364.. _operator-map:
365
366Mapping Operators to Functions
367------------------------------
368
369This table shows how abstract operations correspond to operator symbols in the
370Python syntax and the functions in the :mod:`operator` module.
371
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000372+-----------------------+-------------------------+---------------------------------------+
373| Operation | Syntax | Function |
374+=======================+=========================+=======================================+
375| Addition | ``a + b`` | ``add(a, b)`` |
376+-----------------------+-------------------------+---------------------------------------+
377| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
378+-----------------------+-------------------------+---------------------------------------+
379| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
380+-----------------------+-------------------------+---------------------------------------+
Sandro Tosi83c48822012-02-28 22:28:28 +0100381| Division | ``a / b`` | ``truediv(a, b)`` |
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000382+-----------------------+-------------------------+---------------------------------------+
383| Division | ``a // b`` | ``floordiv(a, b)`` |
384+-----------------------+-------------------------+---------------------------------------+
385| Bitwise And | ``a & b`` | ``and_(a, b)`` |
386+-----------------------+-------------------------+---------------------------------------+
387| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
388+-----------------------+-------------------------+---------------------------------------+
389| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
390+-----------------------+-------------------------+---------------------------------------+
391| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
392+-----------------------+-------------------------+---------------------------------------+
393| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
394+-----------------------+-------------------------+---------------------------------------+
395| Identity | ``a is b`` | ``is_(a, b)`` |
396+-----------------------+-------------------------+---------------------------------------+
397| Identity | ``a is not b`` | ``is_not(a, b)`` |
398+-----------------------+-------------------------+---------------------------------------+
399| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
400+-----------------------+-------------------------+---------------------------------------+
401| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
402+-----------------------+-------------------------+---------------------------------------+
403| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
404+-----------------------+-------------------------+---------------------------------------+
405| Left Shift | ``a << b`` | ``lshift(a, b)`` |
406+-----------------------+-------------------------+---------------------------------------+
407| Modulo | ``a % b`` | ``mod(a, b)`` |
408+-----------------------+-------------------------+---------------------------------------+
409| Multiplication | ``a * b`` | ``mul(a, b)`` |
410+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersond51374e2014-04-09 23:55:56 -0400411| Matrix Multiplication | ``a @ b`` | ``matmul(a, b)`` |
412+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000413| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
414+-----------------------+-------------------------+---------------------------------------+
415| Negation (Logical) | ``not a`` | ``not_(a)`` |
416+-----------------------+-------------------------+---------------------------------------+
417| Positive | ``+ a`` | ``pos(a)`` |
418+-----------------------+-------------------------+---------------------------------------+
419| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
420+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000421| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
422+-----------------------+-------------------------+---------------------------------------+
423| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
424+-----------------------+-------------------------+---------------------------------------+
425| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
426+-----------------------+-------------------------+---------------------------------------+
427| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
428+-----------------------+-------------------------+---------------------------------------+
429| Subtraction | ``a - b`` | ``sub(a, b)`` |
430+-----------------------+-------------------------+---------------------------------------+
431| Truth Test | ``obj`` | ``truth(obj)`` |
432+-----------------------+-------------------------+---------------------------------------+
433| Ordering | ``a < b`` | ``lt(a, b)`` |
434+-----------------------+-------------------------+---------------------------------------+
435| Ordering | ``a <= b`` | ``le(a, b)`` |
436+-----------------------+-------------------------+---------------------------------------+
437| Equality | ``a == b`` | ``eq(a, b)`` |
438+-----------------------+-------------------------+---------------------------------------+
439| Difference | ``a != b`` | ``ne(a, b)`` |
440+-----------------------+-------------------------+---------------------------------------+
441| Ordering | ``a >= b`` | ``ge(a, b)`` |
442+-----------------------+-------------------------+---------------------------------------+
443| Ordering | ``a > b`` | ``gt(a, b)`` |
444+-----------------------+-------------------------+---------------------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000445
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000446Inplace Operators
Sandro Tosi3f7d1d32012-06-01 20:23:20 +0200447-----------------
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000448
449Many operations have an "in-place" version. Listed below are functions
450providing a more primitive access to in-place operators than the usual syntax
451does; for example, the :term:`statement` ``x += y`` is equivalent to
452``x = operator.iadd(x, y)``. Another way to put it is to say that
453``z = operator.iadd(x, y)`` is equivalent to the compound statement
454``z = x; z += y``.
455
456In those examples, note that when an in-place method is called, the computation
457and assignment are performed in two separate steps. The in-place functions
458listed below only do the first step, calling the in-place method. The second
459step, assignment, is not handled.
460
461For immutable targets such as strings, numbers, and tuples, the updated
462value is computed, but not assigned back to the input variable:
463
464>>> a = 'hello'
465>>> iadd(a, ' world')
466'hello world'
467>>> a
468'hello'
469
470For mutable targets such as lists and dictionaries, the inplace method
471will perform the update, so no subsequent assignment is necessary:
472
473>>> s = ['h', 'e', 'l', 'l', 'o']
474>>> iadd(s, [' ', 'w', 'o', 'r', 'l', 'd'])
475['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
476>>> s
477['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
478
479.. function:: iadd(a, b)
480 __iadd__(a, b)
481
482 ``a = iadd(a, b)`` is equivalent to ``a += b``.
483
484
485.. function:: iand(a, b)
486 __iand__(a, b)
487
488 ``a = iand(a, b)`` is equivalent to ``a &= b``.
489
490
491.. function:: iconcat(a, b)
492 __iconcat__(a, b)
493
494 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
495
496
497.. function:: ifloordiv(a, b)
498 __ifloordiv__(a, b)
499
500 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
501
502
503.. function:: ilshift(a, b)
504 __ilshift__(a, b)
505
506 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
507
508
509.. function:: imod(a, b)
510 __imod__(a, b)
511
512 ``a = imod(a, b)`` is equivalent to ``a %= b``.
513
514
515.. function:: imul(a, b)
516 __imul__(a, b)
517
518 ``a = imul(a, b)`` is equivalent to ``a *= b``.
519
520
Benjamin Petersond51374e2014-04-09 23:55:56 -0400521.. function:: imatmul(a, b)
522 __imatmul__(a, b)
523
524 ``a = imatmul(a, b)`` is equivalent to ``a @= b``.
525
526 .. versionadded:: 3.5
527
528
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000529.. function:: ior(a, b)
530 __ior__(a, b)
531
532 ``a = ior(a, b)`` is equivalent to ``a |= b``.
533
534
535.. function:: ipow(a, b)
536 __ipow__(a, b)
537
538 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
539
540
541.. function:: irshift(a, b)
542 __irshift__(a, b)
543
544 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
545
546
547.. function:: isub(a, b)
548 __isub__(a, b)
549
550 ``a = isub(a, b)`` is equivalent to ``a -= b``.
551
552
553.. function:: itruediv(a, b)
554 __itruediv__(a, b)
555
556 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
557
558
559.. function:: ixor(a, b)
560 __ixor__(a, b)
561
562 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.