blob: 36c53556c2685e0112af1979046e4f2809922202 [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.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Georg Brandl116aa622007-08-15 14:28:22 +00007.. sectionauthor:: Skip Montanaro <skip@automatrix.com>
8
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04009**Source code:** :source:`Lib/operator.py`
Georg Brandl116aa622007-08-15 14:28:22 +000010
Christian Heimesfe337bf2008-03-23 21:54:12 +000011.. testsetup::
Georg Brandl48310cd2009-01-03 21:18:54 +000012
Christian Heimesfe337bf2008-03-23 21:54:12 +000013 import operator
Alexander Belopolsky287d1fd2011-01-12 16:37:14 +000014 from operator import itemgetter, iadd
Christian Heimesfe337bf2008-03-23 21:54:12 +000015
Raymond Hettinger3f5228d2013-05-10 19:57:44 -070016--------------
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
Sanket Dasgupta5b9299d2017-09-24 23:59:22 +053020equivalent to the expression ``x+y``. Many function names are those used for
21special methods, without the double underscores. For backward compatibility,
22many of these have a variant with the double underscores kept. The variants
23without the double underscores are preferred for clarity.
Georg Brandl116aa622007-08-15 14:28:22 +000024
25The functions fall into categories that perform object comparisons, logical
Georg Brandlb30f3302011-01-06 09:23:56 +000026operations, mathematical operations and sequence operations.
Georg Brandl116aa622007-08-15 14:28:22 +000027
28The object comparison functions are useful for all objects, and are named after
29the rich comparison operators they support:
30
31
32.. function:: lt(a, b)
33 le(a, b)
34 eq(a, b)
35 ne(a, b)
36 ge(a, b)
37 gt(a, b)
38 __lt__(a, b)
39 __le__(a, b)
40 __eq__(a, b)
41 __ne__(a, b)
42 __ge__(a, b)
43 __gt__(a, b)
44
45 Perform "rich comparisons" between *a* and *b*. Specifically, ``lt(a, b)`` is
46 equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
47 b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
48 ``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
Mark Dickinsonc48d8342009-02-01 14:18:10 +000049 >= b``. Note that these functions can return any value, which may
50 or may not be interpretable as a Boolean value. See
51 :ref:`comparisons` for more information about rich comparisons.
Georg Brandl116aa622007-08-15 14:28:22 +000052
Georg Brandl116aa622007-08-15 14:28:22 +000053
54The logical operations are also generally applicable to all objects, and support
55truth tests, identity tests, and boolean operations:
56
57
Thomas Wouters1b7f8912007-09-19 03:06:30 +000058.. function:: not_(obj)
59 __not__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000060
Thomas Wouters1b7f8912007-09-19 03:06:30 +000061 Return the outcome of :keyword:`not` *obj*. (Note that there is no
Georg Brandl116aa622007-08-15 14:28:22 +000062 :meth:`__not__` method for object instances; only the interpreter core defines
63 this operation. The result is affected by the :meth:`__bool__` and
64 :meth:`__len__` methods.)
65
66
Thomas Wouters1b7f8912007-09-19 03:06:30 +000067.. function:: truth(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000068
Thomas Wouters1b7f8912007-09-19 03:06:30 +000069 Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
Georg Brandl116aa622007-08-15 14:28:22 +000070 equivalent to using the :class:`bool` constructor.
71
72
73.. function:: is_(a, b)
74
75 Return ``a is b``. Tests object identity.
76
Georg Brandl116aa622007-08-15 14:28:22 +000077
78.. function:: is_not(a, b)
79
80 Return ``a is not b``. Tests object identity.
81
Georg Brandl116aa622007-08-15 14:28:22 +000082
83The mathematical and bitwise operations are the most numerous:
84
85
Thomas Wouters1b7f8912007-09-19 03:06:30 +000086.. function:: abs(obj)
87 __abs__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000088
Thomas Wouters1b7f8912007-09-19 03:06:30 +000089 Return the absolute value of *obj*.
Georg Brandl116aa622007-08-15 14:28:22 +000090
91
92.. function:: add(a, b)
93 __add__(a, b)
94
95 Return ``a + b``, for *a* and *b* numbers.
96
97
98.. function:: and_(a, b)
99 __and__(a, b)
100
101 Return the bitwise and of *a* and *b*.
102
103
Georg Brandl116aa622007-08-15 14:28:22 +0000104.. function:: floordiv(a, b)
105 __floordiv__(a, b)
106
107 Return ``a // b``.
108
Georg Brandl116aa622007-08-15 14:28:22 +0000109
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000110.. function:: index(a)
111 __index__(a)
112
113 Return *a* converted to an integer. Equivalent to ``a.__index__()``.
114
Serhiy Storchaka5f4b229d2020-05-28 10:33:45 +0300115 .. versionchanged:: 3.10
116 The result always has exact type :class:`int`. Previously, the result
117 could have been an instance of a subclass of ``int``.
118
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000119
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000120.. function:: inv(obj)
121 invert(obj)
122 __inv__(obj)
123 __invert__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000124
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000125 Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
Georg Brandl116aa622007-08-15 14:28:22 +0000126
Georg Brandl116aa622007-08-15 14:28:22 +0000127
128.. function:: lshift(a, b)
129 __lshift__(a, b)
130
131 Return *a* shifted left by *b*.
132
133
134.. function:: mod(a, b)
135 __mod__(a, b)
136
137 Return ``a % b``.
138
139
140.. function:: mul(a, b)
141 __mul__(a, b)
142
143 Return ``a * b``, for *a* and *b* numbers.
144
145
Benjamin Petersond51374e2014-04-09 23:55:56 -0400146.. function:: matmul(a, b)
147 __matmul__(a, b)
148
149 Return ``a @ b``.
150
151 .. versionadded:: 3.5
152
153
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000154.. function:: neg(obj)
155 __neg__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000156
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000157 Return *obj* negated (``-obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000158
159
160.. function:: or_(a, b)
161 __or__(a, b)
162
163 Return the bitwise or of *a* and *b*.
164
165
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000166.. function:: pos(obj)
167 __pos__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000168
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000169 Return *obj* positive (``+obj``).
Georg Brandl116aa622007-08-15 14:28:22 +0000170
171
172.. function:: pow(a, b)
173 __pow__(a, b)
174
175 Return ``a ** b``, for *a* and *b* numbers.
176
Georg Brandl116aa622007-08-15 14:28:22 +0000177
178.. function:: rshift(a, b)
179 __rshift__(a, b)
180
181 Return *a* shifted right by *b*.
182
183
184.. function:: sub(a, b)
185 __sub__(a, b)
186
187 Return ``a - b``.
188
189
190.. function:: truediv(a, b)
191 __truediv__(a, b)
192
Georg Brandlf6945182008-02-01 11:56:49 +0000193 Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
194 "true" division.
Georg Brandl116aa622007-08-15 14:28:22 +0000195
Georg Brandl116aa622007-08-15 14:28:22 +0000196
197.. function:: xor(a, b)
198 __xor__(a, b)
199
200 Return the bitwise exclusive or of *a* and *b*.
201
202
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000203Operations which work with sequences (some of them with mappings too) include:
Georg Brandl116aa622007-08-15 14:28:22 +0000204
205.. function:: concat(a, b)
206 __concat__(a, b)
207
208 Return ``a + b`` for *a* and *b* sequences.
209
210
211.. function:: contains(a, b)
212 __contains__(a, b)
213
214 Return the outcome of the test ``b in a``. Note the reversed operands.
215
Georg Brandl116aa622007-08-15 14:28:22 +0000216
217.. function:: countOf(a, b)
218
219 Return the number of occurrences of *b* in *a*.
220
221
222.. function:: delitem(a, b)
223 __delitem__(a, b)
224
225 Remove the value of *a* at index *b*.
226
Georg Brandl48310cd2009-01-03 21:18:54 +0000227
Georg Brandl116aa622007-08-15 14:28:22 +0000228.. function:: getitem(a, b)
229 __getitem__(a, b)
230
231 Return the value of *a* at index *b*.
232
233
Georg Brandl116aa622007-08-15 14:28:22 +0000234.. function:: indexOf(a, b)
235
236 Return the index of the first of occurrence of *b* in *a*.
237
238
Georg Brandl116aa622007-08-15 14:28:22 +0000239.. function:: setitem(a, b, c)
240 __setitem__(a, b, c)
241
242 Set the value of *a* at index *b* to *c*.
243
Georg Brandl116aa622007-08-15 14:28:22 +0000244
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200245.. function:: length_hint(obj, default=0)
246
R David Murraye8db1622014-03-10 15:00:33 -0400247 Return an estimated length for the object *o*. First try to return its
Ezio Melottie12dc282012-10-07 12:09:36 +0300248 actual length, then an estimate using :meth:`object.__length_hint__`, and
R David Murraye8db1622014-03-10 15:00:33 -0400249 finally return the default value.
Armin Ronacheraa9a79d2012-10-06 14:03:24 +0200250
Armin Ronacher74b38b12012-10-07 10:29:32 +0200251 .. versionadded:: 3.4
252
Georg Brandl116aa622007-08-15 14:28:22 +0000253The :mod:`operator` module also defines tools for generalized attribute and item
254lookups. These are useful for making fast field extractors as arguments for
255:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
256expect a function argument.
257
258
Ezio Melottibabc8222013-05-08 10:53:11 +0300259.. function:: attrgetter(attr)
260 attrgetter(*attrs)
Georg Brandl116aa622007-08-15 14:28:22 +0000261
Ezio Melottibabc8222013-05-08 10:53:11 +0300262 Return a callable object that fetches *attr* from its operand.
263 If more than one attribute is requested, returns a tuple of attributes.
264 The attribute names can also contain dots. For example:
265
266 * After ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``.
267
268 * After ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns
269 ``(b.name, b.date)``.
270
271 * After ``f = attrgetter('name.first', 'name.last')``, the call ``f(b)``
Zachary Ware0bffca02013-12-18 12:21:49 -0600272 returns ``(b.name.first, b.name.last)``.
Ezio Melottibabc8222013-05-08 10:53:11 +0300273
274 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000275
276 def attrgetter(*items):
Antoine Pitroue9745712010-10-31 15:26:04 +0000277 if any(not isinstance(item, str) for item in items):
278 raise TypeError('attribute name must be a string')
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000279 if len(items) == 1:
280 attr = items[0]
281 def g(obj):
282 return resolve_attr(obj, attr)
283 else:
284 def g(obj):
Georg Brandlf6d63472013-10-06 19:14:35 +0200285 return tuple(resolve_attr(obj, attr) for attr in items)
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000286 return g
287
288 def resolve_attr(obj, attr):
289 for name in attr.split("."):
290 obj = getattr(obj, name)
291 return obj
292
Georg Brandl116aa622007-08-15 14:28:22 +0000293
Ezio Melottibabc8222013-05-08 10:53:11 +0300294.. function:: itemgetter(item)
295 itemgetter(*items)
Georg Brandl116aa622007-08-15 14:28:22 +0000296
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000297 Return a callable object that fetches *item* from its operand using the
298 operand's :meth:`__getitem__` method. If multiple items are specified,
Ezio Melottibabc8222013-05-08 10:53:11 +0300299 returns a tuple of lookup values. For example:
300
301 * After ``f = itemgetter(2)``, the call ``f(r)`` returns ``r[2]``.
302
303 * After ``g = itemgetter(2, 5, 3)``, the call ``g(r)`` returns
304 ``(r[2], r[5], r[3])``.
305
306 Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000307
Benjamin Petersonffec8102010-08-21 20:01:28 +0000308 def itemgetter(*items):
309 if len(items) == 1:
310 item = items[0]
311 def g(obj):
312 return obj[item]
313 else:
314 def g(obj):
315 return tuple(obj[item] for item in items)
316 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000317
318 The items can be any type accepted by the operand's :meth:`__getitem__`
319 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000320 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000321
WeizhongTuffa2c3e2018-04-13 09:33:08 +0800322 >>> itemgetter('name')({'name': 'tu', 'age': 18})
323 'tu'
Christian Heimesfe337bf2008-03-23 21:54:12 +0000324 >>> itemgetter(1)('ABCDEFG')
325 'B'
326 >>> itemgetter(1,3,5)('ABCDEFG')
327 ('B', 'D', 'F')
328 >>> itemgetter(slice(2,None))('ABCDEFG')
329 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000330
Raymond Hettinger70c2dd32017-09-07 23:53:07 -0700331 >>> soldier = dict(rank='captain', name='dotterbart')
332 >>> itemgetter('rank')(soldier)
333 'captain'
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000334
335 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000336 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000337
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000338 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
339 >>> getcount = itemgetter(1)
Raymond Hettingerd292a172010-09-01 07:46:54 +0000340 >>> list(map(getcount, inventory))
Benjamin Petersonc16f8b32010-08-21 20:03:15 +0000341 [3, 2, 5, 1]
342 >>> sorted(inventory, key=getcount)
343 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000344
345
Serhiy Storchaka2085bd02019-06-01 11:00:15 +0300346.. function:: methodcaller(name, /, *args, **kwargs)
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000347
348 Return a callable object that calls the method *name* on its operand. If
349 additional arguments and/or keyword arguments are given, they will be given
Ezio Melottibabc8222013-05-08 10:53:11 +0300350 to the method as well. For example:
351
352 * After ``f = methodcaller('name')``, the call ``f(b)`` returns ``b.name()``.
353
354 * After ``f = methodcaller('name', 'foo', bar=1)``, the call ``f(b)``
355 returns ``b.name('foo', bar=1)``.
356
357 Equivalent to::
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000358
Serhiy Storchaka2085bd02019-06-01 11:00:15 +0300359 def methodcaller(name, /, *args, **kwargs):
Benjamin Peterson2d55e2a2010-08-21 20:08:36 +0000360 def caller(obj):
361 return getattr(obj, name)(*args, **kwargs)
362 return caller
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000363
364
Georg Brandl116aa622007-08-15 14:28:22 +0000365.. _operator-map:
366
367Mapping Operators to Functions
368------------------------------
369
370This table shows how abstract operations correspond to operator symbols in the
371Python syntax and the functions in the :mod:`operator` module.
372
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000373+-----------------------+-------------------------+---------------------------------------+
374| Operation | Syntax | Function |
375+=======================+=========================+=======================================+
376| Addition | ``a + b`` | ``add(a, b)`` |
377+-----------------------+-------------------------+---------------------------------------+
378| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
379+-----------------------+-------------------------+---------------------------------------+
380| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
381+-----------------------+-------------------------+---------------------------------------+
Sandro Tosi83c48822012-02-28 22:28:28 +0100382| Division | ``a / b`` | ``truediv(a, b)`` |
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000383+-----------------------+-------------------------+---------------------------------------+
384| Division | ``a // b`` | ``floordiv(a, b)`` |
385+-----------------------+-------------------------+---------------------------------------+
386| Bitwise And | ``a & b`` | ``and_(a, b)`` |
387+-----------------------+-------------------------+---------------------------------------+
388| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
389+-----------------------+-------------------------+---------------------------------------+
390| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
391+-----------------------+-------------------------+---------------------------------------+
392| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
393+-----------------------+-------------------------+---------------------------------------+
394| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
395+-----------------------+-------------------------+---------------------------------------+
396| Identity | ``a is b`` | ``is_(a, b)`` |
397+-----------------------+-------------------------+---------------------------------------+
398| Identity | ``a is not b`` | ``is_not(a, b)`` |
399+-----------------------+-------------------------+---------------------------------------+
400| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
401+-----------------------+-------------------------+---------------------------------------+
402| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
403+-----------------------+-------------------------+---------------------------------------+
404| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
405+-----------------------+-------------------------+---------------------------------------+
406| Left Shift | ``a << b`` | ``lshift(a, b)`` |
407+-----------------------+-------------------------+---------------------------------------+
408| Modulo | ``a % b`` | ``mod(a, b)`` |
409+-----------------------+-------------------------+---------------------------------------+
410| Multiplication | ``a * b`` | ``mul(a, b)`` |
411+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersond51374e2014-04-09 23:55:56 -0400412| Matrix Multiplication | ``a @ b`` | ``matmul(a, b)`` |
413+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000414| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
415+-----------------------+-------------------------+---------------------------------------+
416| Negation (Logical) | ``not a`` | ``not_(a)`` |
417+-----------------------+-------------------------+---------------------------------------+
418| Positive | ``+ a`` | ``pos(a)`` |
419+-----------------------+-------------------------+---------------------------------------+
420| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
421+-----------------------+-------------------------+---------------------------------------+
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000422| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
423+-----------------------+-------------------------+---------------------------------------+
424| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
425+-----------------------+-------------------------+---------------------------------------+
426| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
427+-----------------------+-------------------------+---------------------------------------+
428| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
429+-----------------------+-------------------------+---------------------------------------+
430| Subtraction | ``a - b`` | ``sub(a, b)`` |
431+-----------------------+-------------------------+---------------------------------------+
432| Truth Test | ``obj`` | ``truth(obj)`` |
433+-----------------------+-------------------------+---------------------------------------+
434| Ordering | ``a < b`` | ``lt(a, b)`` |
435+-----------------------+-------------------------+---------------------------------------+
436| Ordering | ``a <= b`` | ``le(a, b)`` |
437+-----------------------+-------------------------+---------------------------------------+
438| Equality | ``a == b`` | ``eq(a, b)`` |
439+-----------------------+-------------------------+---------------------------------------+
440| Difference | ``a != b`` | ``ne(a, b)`` |
441+-----------------------+-------------------------+---------------------------------------+
442| Ordering | ``a >= b`` | ``ge(a, b)`` |
443+-----------------------+-------------------------+---------------------------------------+
444| Ordering | ``a > b`` | ``gt(a, b)`` |
445+-----------------------+-------------------------+---------------------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000446
Andre Delfinof4efa312019-04-08 06:14:43 -0300447In-place Operators
448------------------
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000449
450Many operations have an "in-place" version. Listed below are functions
451providing a more primitive access to in-place operators than the usual syntax
452does; for example, the :term:`statement` ``x += y`` is equivalent to
453``x = operator.iadd(x, y)``. Another way to put it is to say that
454``z = operator.iadd(x, y)`` is equivalent to the compound statement
455``z = x; z += y``.
456
457In those examples, note that when an in-place method is called, the computation
458and assignment are performed in two separate steps. The in-place functions
459listed below only do the first step, calling the in-place method. The second
460step, assignment, is not handled.
461
462For immutable targets such as strings, numbers, and tuples, the updated
463value is computed, but not assigned back to the input variable:
464
465>>> a = 'hello'
466>>> iadd(a, ' world')
467'hello world'
468>>> a
469'hello'
470
Andre Delfinof4efa312019-04-08 06:14:43 -0300471For mutable targets such as lists and dictionaries, the in-place method
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000472will perform the update, so no subsequent assignment is necessary:
473
474>>> s = ['h', 'e', 'l', 'l', 'o']
475>>> iadd(s, [' ', 'w', 'o', 'r', 'l', 'd'])
476['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
477>>> s
478['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
479
480.. function:: iadd(a, b)
481 __iadd__(a, b)
482
483 ``a = iadd(a, b)`` is equivalent to ``a += b``.
484
485
486.. function:: iand(a, b)
487 __iand__(a, b)
488
489 ``a = iand(a, b)`` is equivalent to ``a &= b``.
490
491
492.. function:: iconcat(a, b)
493 __iconcat__(a, b)
494
495 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
496
497
498.. function:: ifloordiv(a, b)
499 __ifloordiv__(a, b)
500
501 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
502
503
504.. function:: ilshift(a, b)
505 __ilshift__(a, b)
506
507 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
508
509
510.. function:: imod(a, b)
511 __imod__(a, b)
512
513 ``a = imod(a, b)`` is equivalent to ``a %= b``.
514
515
516.. function:: imul(a, b)
517 __imul__(a, b)
518
519 ``a = imul(a, b)`` is equivalent to ``a *= b``.
520
521
Benjamin Petersond51374e2014-04-09 23:55:56 -0400522.. function:: imatmul(a, b)
523 __imatmul__(a, b)
524
525 ``a = imatmul(a, b)`` is equivalent to ``a @= b``.
526
527 .. versionadded:: 3.5
528
529
Raymond Hettinger83b1ab02011-01-08 10:26:53 +0000530.. function:: ior(a, b)
531 __ior__(a, b)
532
533 ``a = ior(a, b)`` is equivalent to ``a |= b``.
534
535
536.. function:: ipow(a, b)
537 __ipow__(a, b)
538
539 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
540
541
542.. function:: irshift(a, b)
543 __irshift__(a, b)
544
545 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
546
547
548.. function:: isub(a, b)
549 __isub__(a, b)
550
551 ``a = isub(a, b)`` is equivalent to ``a -= b``.
552
553
554.. function:: itruediv(a, b)
555 __itruediv__(a, b)
556
557 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
558
559
560.. function:: ixor(a, b)
561 __ixor__(a, b)
562
563 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.