blob: 047c7ec6dc1b674143f8091a4dc97ef23f1d1b73 [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::
10
11 import operator
12 from operator import itemgetter
13
Georg Brandl116aa622007-08-15 14:28:22 +000014
15The :mod:`operator` module exports a set of functions implemented in C
16corresponding to the intrinsic operators of Python. For example,
17``operator.add(x, y)`` is equivalent to the expression ``x+y``. The function
18names are those used for special class methods; variants without leading and
19trailing ``__`` are also provided for convenience.
20
21The functions fall into categories that perform object comparisons, logical
22operations, mathematical operations, sequence operations, and abstract type
23tests.
24
25The object comparison functions are useful for all objects, and are named after
26the rich comparison operators they support:
27
28
29.. function:: lt(a, b)
30 le(a, b)
31 eq(a, b)
32 ne(a, b)
33 ge(a, b)
34 gt(a, b)
35 __lt__(a, b)
36 __le__(a, b)
37 __eq__(a, b)
38 __ne__(a, b)
39 __ge__(a, b)
40 __gt__(a, b)
41
42 Perform "rich comparisons" between *a* and *b*. Specifically, ``lt(a, b)`` is
43 equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
44 b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
45 ``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
46 >= b``. Note that unlike the built-in :func:`cmp`, these functions can
47 return any value, which may or may not be interpretable as a Boolean value.
48 See :ref:`comparisons` for more information about rich comparisons.
49
Georg Brandl116aa622007-08-15 14:28:22 +000050
51The logical operations are also generally applicable to all objects, and support
52truth tests, identity tests, and boolean operations:
53
54
Thomas Wouters1b7f8912007-09-19 03:06:30 +000055.. function:: not_(obj)
56 __not__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000057
Thomas Wouters1b7f8912007-09-19 03:06:30 +000058 Return the outcome of :keyword:`not` *obj*. (Note that there is no
Georg Brandl116aa622007-08-15 14:28:22 +000059 :meth:`__not__` method for object instances; only the interpreter core defines
60 this operation. The result is affected by the :meth:`__bool__` and
61 :meth:`__len__` methods.)
62
63
Thomas Wouters1b7f8912007-09-19 03:06:30 +000064.. function:: truth(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000065
Thomas Wouters1b7f8912007-09-19 03:06:30 +000066 Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
Georg Brandl116aa622007-08-15 14:28:22 +000067 equivalent to using the :class:`bool` constructor.
68
69
70.. function:: is_(a, b)
71
72 Return ``a is b``. Tests object identity.
73
Georg Brandl116aa622007-08-15 14:28:22 +000074
75.. function:: is_not(a, b)
76
77 Return ``a is not b``. Tests object identity.
78
Georg Brandl116aa622007-08-15 14:28:22 +000079
80The mathematical and bitwise operations are the most numerous:
81
82
Thomas Wouters1b7f8912007-09-19 03:06:30 +000083.. function:: abs(obj)
84 __abs__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +000085
Thomas Wouters1b7f8912007-09-19 03:06:30 +000086 Return the absolute value of *obj*.
Georg Brandl116aa622007-08-15 14:28:22 +000087
88
89.. function:: add(a, b)
90 __add__(a, b)
91
92 Return ``a + b``, for *a* and *b* numbers.
93
94
95.. function:: and_(a, b)
96 __and__(a, b)
97
98 Return the bitwise and of *a* and *b*.
99
100
Georg Brandl116aa622007-08-15 14:28:22 +0000101.. function:: floordiv(a, b)
102 __floordiv__(a, b)
103
104 Return ``a // b``.
105
Georg Brandl116aa622007-08-15 14:28:22 +0000106
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000107.. function:: inv(obj)
108 invert(obj)
109 __inv__(obj)
110 __invert__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000111
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000112 Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
Georg Brandl116aa622007-08-15 14:28:22 +0000113
Georg Brandl116aa622007-08-15 14:28:22 +0000114
115.. function:: lshift(a, b)
116 __lshift__(a, b)
117
118 Return *a* shifted left by *b*.
119
120
121.. function:: mod(a, b)
122 __mod__(a, b)
123
124 Return ``a % b``.
125
126
127.. function:: mul(a, b)
128 __mul__(a, b)
129
130 Return ``a * b``, for *a* and *b* numbers.
131
132
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000133.. function:: neg(obj)
134 __neg__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000135
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000136 Return *obj* negated.
Georg Brandl116aa622007-08-15 14:28:22 +0000137
138
139.. function:: or_(a, b)
140 __or__(a, b)
141
142 Return the bitwise or of *a* and *b*.
143
144
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000145.. function:: pos(obj)
146 __pos__(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000147
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000148 Return *obj* positive.
Georg Brandl116aa622007-08-15 14:28:22 +0000149
150
151.. function:: pow(a, b)
152 __pow__(a, b)
153
154 Return ``a ** b``, for *a* and *b* numbers.
155
Georg Brandl116aa622007-08-15 14:28:22 +0000156
157.. function:: rshift(a, b)
158 __rshift__(a, b)
159
160 Return *a* shifted right by *b*.
161
162
163.. function:: sub(a, b)
164 __sub__(a, b)
165
166 Return ``a - b``.
167
168
169.. function:: truediv(a, b)
170 __truediv__(a, b)
171
Georg Brandlf6945182008-02-01 11:56:49 +0000172 Return ``a / b`` where 2/3 is .66 rather than 0. This is also known as
173 "true" division.
Georg Brandl116aa622007-08-15 14:28:22 +0000174
Georg Brandl116aa622007-08-15 14:28:22 +0000175
176.. function:: xor(a, b)
177 __xor__(a, b)
178
179 Return the bitwise exclusive or of *a* and *b*.
180
181
182.. function:: index(a)
183 __index__(a)
184
185 Return *a* converted to an integer. Equivalent to ``a.__index__()``.
186
Georg Brandl116aa622007-08-15 14:28:22 +0000187
188Operations which work with sequences include:
189
190.. function:: concat(a, b)
191 __concat__(a, b)
192
193 Return ``a + b`` for *a* and *b* sequences.
194
195
196.. function:: contains(a, b)
197 __contains__(a, b)
198
199 Return the outcome of the test ``b in a``. Note the reversed operands.
200
Georg Brandl116aa622007-08-15 14:28:22 +0000201
202.. function:: countOf(a, b)
203
204 Return the number of occurrences of *b* in *a*.
205
206
207.. function:: delitem(a, b)
208 __delitem__(a, b)
209
210 Remove the value of *a* at index *b*.
211
Georg Brandlf6945182008-02-01 11:56:49 +0000212
Georg Brandl116aa622007-08-15 14:28:22 +0000213.. function:: delslice(a, b, c)
214 __delslice__(a, b, c)
215
216 Delete the slice of *a* from index *b* to index *c-1*.
217
218
219.. function:: getitem(a, b)
220 __getitem__(a, b)
221
222 Return the value of *a* at index *b*.
223
224
225.. function:: getslice(a, b, c)
226 __getslice__(a, b, c)
227
228 Return the slice of *a* from index *b* to index *c-1*.
229
230
231.. function:: indexOf(a, b)
232
233 Return the index of the first of occurrence of *b* in *a*.
234
235
236.. function:: repeat(a, b)
237 __repeat__(a, b)
238
239 Return ``a * b`` where *a* is a sequence and *b* is an integer.
240
241
Georg Brandl116aa622007-08-15 14:28:22 +0000242.. function:: setitem(a, b, c)
243 __setitem__(a, b, c)
244
245 Set the value of *a* at index *b* to *c*.
246
247
248.. function:: setslice(a, b, c, v)
249 __setslice__(a, b, c, v)
250
251 Set the slice of *a* from index *b* to index *c-1* to the sequence *v*.
252
Georg Brandlf6945182008-02-01 11:56:49 +0000253
Georg Brandl116aa622007-08-15 14:28:22 +0000254Many operations have an "in-place" version. The following functions provide a
255more primitive access to in-place operators than the usual syntax does; for
Christian Heimesd8654cf2007-12-02 15:22:16 +0000256example, the :term:`statement` ``x += y`` is equivalent to
257``x = operator.iadd(x, y)``. Another way to put it is to say that
258``z = operator.iadd(x, y)`` is equivalent to the compound statement
259``z = x; z += y``.
Georg Brandl116aa622007-08-15 14:28:22 +0000260
261.. function:: iadd(a, b)
262 __iadd__(a, b)
263
264 ``a = iadd(a, b)`` is equivalent to ``a += b``.
265
Georg Brandl116aa622007-08-15 14:28:22 +0000266
267.. function:: iand(a, b)
268 __iand__(a, b)
269
270 ``a = iand(a, b)`` is equivalent to ``a &= b``.
271
Georg Brandl116aa622007-08-15 14:28:22 +0000272
273.. function:: iconcat(a, b)
274 __iconcat__(a, b)
275
276 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
277
Georg Brandl116aa622007-08-15 14:28:22 +0000278
Georg Brandl116aa622007-08-15 14:28:22 +0000279.. function:: ifloordiv(a, b)
280 __ifloordiv__(a, b)
281
282 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
283
Georg Brandl116aa622007-08-15 14:28:22 +0000284
285.. function:: ilshift(a, b)
286 __ilshift__(a, b)
287
Georg Brandl55ac8f02007-09-01 13:51:09 +0000288 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
Georg Brandl116aa622007-08-15 14:28:22 +0000289
290
291.. function:: imod(a, b)
292 __imod__(a, b)
293
294 ``a = imod(a, b)`` is equivalent to ``a %= b``.
295
Georg Brandl116aa622007-08-15 14:28:22 +0000296
297.. function:: imul(a, b)
298 __imul__(a, b)
299
300 ``a = imul(a, b)`` is equivalent to ``a *= b``.
301
Georg Brandl116aa622007-08-15 14:28:22 +0000302
303.. function:: ior(a, b)
304 __ior__(a, b)
305
306 ``a = ior(a, b)`` is equivalent to ``a |= b``.
307
Georg Brandl116aa622007-08-15 14:28:22 +0000308
309.. function:: ipow(a, b)
310 __ipow__(a, b)
311
312 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
313
Georg Brandl116aa622007-08-15 14:28:22 +0000314
315.. function:: irepeat(a, b)
316 __irepeat__(a, b)
317
318 ``a = irepeat(a, b)`` is equivalent to ``a *= b`` where *a* is a sequence and
319 *b* is an integer.
320
Georg Brandl116aa622007-08-15 14:28:22 +0000321
322.. function:: irshift(a, b)
323 __irshift__(a, b)
324
325 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
326
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328.. function:: isub(a, b)
329 __isub__(a, b)
330
331 ``a = isub(a, b)`` is equivalent to ``a -= b``.
332
Georg Brandl116aa622007-08-15 14:28:22 +0000333
334.. function:: itruediv(a, b)
335 __itruediv__(a, b)
336
Georg Brandlf6945182008-02-01 11:56:49 +0000337 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
Georg Brandl116aa622007-08-15 14:28:22 +0000338
Georg Brandl116aa622007-08-15 14:28:22 +0000339
340.. function:: ixor(a, b)
341 __ixor__(a, b)
342
343 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.
344
Georg Brandl116aa622007-08-15 14:28:22 +0000345
346The :mod:`operator` module also defines a few predicates to test the type of
347objects.
348
Georg Brandlf6945182008-02-01 11:56:49 +0000349.. XXX just remove them?
Georg Brandl116aa622007-08-15 14:28:22 +0000350.. note::
351
Georg Brandlf6945182008-02-01 11:56:49 +0000352 Be careful not to misinterpret the results of these functions; none have any
353 measure of reliability with instance objects.
Christian Heimesfe337bf2008-03-23 21:54:12 +0000354 For example:
Georg Brandl116aa622007-08-15 14:28:22 +0000355
356 >>> class C:
357 ... pass
358 ...
359 >>> import operator
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000360 >>> obj = C()
361 >>> operator.isMappingType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000362 True
363
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000364.. note::
Georg Brandl116aa622007-08-15 14:28:22 +0000365
Georg Brandlf6945182008-02-01 11:56:49 +0000366 Since there are now abstract classes for collection types, you should write,
367 for example, ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000368 collections.Sequence)``.
369
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000370.. function:: isMappingType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000371
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000372 Returns true if the object *obj* supports the mapping interface. This is true for
Georg Brandl116aa622007-08-15 14:28:22 +0000373 dictionaries and all instance objects defining :meth:`__getitem__`.
374
375 .. warning::
376
377 There is no reliable way to test if an instance supports the complete mapping
378 protocol since the interface itself is ill-defined. This makes this test less
379 useful than it otherwise might be.
380
381
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000382.. function:: isNumberType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000383
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000384 Returns true if the object *obj* represents a number. This is true for all
Georg Brandl116aa622007-08-15 14:28:22 +0000385 numeric types implemented in C.
386
387 .. warning::
388
389 There is no reliable way to test if an instance supports the complete numeric
390 interface since the interface itself is ill-defined. This makes this test less
391 useful than it otherwise might be.
392
393
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000394.. function:: isSequenceType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000395
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000396 Returns true if the object *obj* supports the sequence protocol. This returns true
Georg Brandl116aa622007-08-15 14:28:22 +0000397 for all objects which define sequence methods in C, and for all instance objects
398 defining :meth:`__getitem__`.
399
400 .. warning::
401
402 There is no reliable way to test if an instance supports the complete sequence
403 interface since the interface itself is ill-defined. This makes this test less
404 useful than it otherwise might be.
405
406Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
Christian Heimesfe337bf2008-03-23 21:54:12 +0000407their character equivalents.
Georg Brandl116aa622007-08-15 14:28:22 +0000408
Georg Brandl116aa622007-08-15 14:28:22 +0000409 >>> d = {}
410 >>> keys = range(256)
411 >>> vals = map(chr, keys)
Christian Heimesfe337bf2008-03-23 21:54:12 +0000412 >>> map(operator.setitem, [d]*len(keys), keys, vals) # doctest: +SKIP
Georg Brandl116aa622007-08-15 14:28:22 +0000413
414.. XXX: find a better, readable, example
415
416The :mod:`operator` module also defines tools for generalized attribute and item
417lookups. These are useful for making fast field extractors as arguments for
418:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
419expect a function argument.
420
421
422.. function:: attrgetter(attr[, args...])
423
424 Return a callable object that fetches *attr* from its operand. If more than one
425 attribute is requested, returns a tuple of attributes. After,
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000426 ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After,
427 ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name,
Georg Brandl116aa622007-08-15 14:28:22 +0000428 b.date)``.
429
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000430 The attribute names can also contain dots; after ``f = attrgetter('date.month')``,
431 the call ``f(b)`` returns ``b.date.month``.
Georg Brandl116aa622007-08-15 14:28:22 +0000432
433.. function:: itemgetter(item[, args...])
434
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000435 Return a callable object that fetches *item* from its operand using the
436 operand's :meth:`__getitem__` method. If multiple items are specified,
437 returns a tuple of lookup values. Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000438
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000439 def itemgetter(*items):
440 if len(items) == 1:
441 item = items[0]
442 def g(obj):
443 return obj[item]
444 else:
445 def g(obj):
446 return tuple(obj[item] for item in items)
447 return g
448
449 The items can be any type accepted by the operand's :meth:`__getitem__`
450 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000451 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000452
Christian Heimesfe337bf2008-03-23 21:54:12 +0000453 >>> itemgetter(1)('ABCDEFG')
454 'B'
455 >>> itemgetter(1,3,5)('ABCDEFG')
456 ('B', 'D', 'F')
457 >>> itemgetter(slice(2,None))('ABCDEFG')
458 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000459
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000460 .. versionadded:: 2.4
461
462 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000463 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000464
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000465 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
466 >>> getcount = itemgetter(1)
467 >>> map(getcount, inventory)
468 [3, 2, 5, 1]
469 >>> sorted(inventory, key=getcount)
470 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000471
472
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000473.. function:: methodcaller(name[, args...])
474
475 Return a callable object that calls the method *name* on its operand. If
476 additional arguments and/or keyword arguments are given, they will be given
477 to the method as well. After ``f = methodcaller('name')``, the call ``f(b)``
478 returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the
479 call ``f(b)`` returns ``b.name('foo', bar=1)``.
480
481
Georg Brandl116aa622007-08-15 14:28:22 +0000482.. _operator-map:
483
484Mapping Operators to Functions
485------------------------------
486
487This table shows how abstract operations correspond to operator symbols in the
488Python syntax and the functions in the :mod:`operator` module.
489
490+-----------------------+-------------------------+---------------------------------+
491| Operation | Syntax | Function |
492+=======================+=========================+=================================+
493| Addition | ``a + b`` | ``add(a, b)`` |
494+-----------------------+-------------------------+---------------------------------+
495| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
496+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000497| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000498+-----------------------+-------------------------+---------------------------------+
Georg Brandlf6945182008-02-01 11:56:49 +0000499| Division | ``a / b`` | ``truediv(a, b)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000500+-----------------------+-------------------------+---------------------------------+
501| Division | ``a // b`` | ``floordiv(a, b)`` |
502+-----------------------+-------------------------+---------------------------------+
503| Bitwise And | ``a & b`` | ``and_(a, b)`` |
504+-----------------------+-------------------------+---------------------------------+
505| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
506+-----------------------+-------------------------+---------------------------------+
507| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
508+-----------------------+-------------------------+---------------------------------+
509| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
510+-----------------------+-------------------------+---------------------------------+
511| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
512+-----------------------+-------------------------+---------------------------------+
513| Identity | ``a is b`` | ``is_(a, b)`` |
514+-----------------------+-------------------------+---------------------------------+
515| Identity | ``a is not b`` | ``is_not(a, b)`` |
516+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000517| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000518+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000519| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000520+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000521| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000522+-----------------------+-------------------------+---------------------------------+
523| Left Shift | ``a << b`` | ``lshift(a, b)`` |
524+-----------------------+-------------------------+---------------------------------+
525| Modulo | ``a % b`` | ``mod(a, b)`` |
526+-----------------------+-------------------------+---------------------------------+
527| Multiplication | ``a * b`` | ``mul(a, b)`` |
528+-----------------------+-------------------------+---------------------------------+
529| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
530+-----------------------+-------------------------+---------------------------------+
531| Negation (Logical) | ``not a`` | ``not_(a)`` |
532+-----------------------+-------------------------+---------------------------------+
533| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
534+-----------------------+-------------------------+---------------------------------+
535| Sequence Repitition | ``seq * i`` | ``repeat(seq, i)`` |
536+-----------------------+-------------------------+---------------------------------+
537| Slice Assignment | ``seq[i:j] = values`` | ``setslice(seq, i, j, values)`` |
538+-----------------------+-------------------------+---------------------------------+
539| Slice Deletion | ``del seq[i:j]`` | ``delslice(seq, i, j)`` |
540+-----------------------+-------------------------+---------------------------------+
541| Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` |
542+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000543| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000544+-----------------------+-------------------------+---------------------------------+
545| Subtraction | ``a - b`` | ``sub(a, b)`` |
546+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000547| Truth Test | ``obj`` | ``truth(obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000548+-----------------------+-------------------------+---------------------------------+
549| Ordering | ``a < b`` | ``lt(a, b)`` |
550+-----------------------+-------------------------+---------------------------------+
551| Ordering | ``a <= b`` | ``le(a, b)`` |
552+-----------------------+-------------------------+---------------------------------+
553| Equality | ``a == b`` | ``eq(a, b)`` |
554+-----------------------+-------------------------+---------------------------------+
555| Difference | ``a != b`` | ``ne(a, b)`` |
556+-----------------------+-------------------------+---------------------------------+
557| Ordering | ``a >= b`` | ``ge(a, b)`` |
558+-----------------------+-------------------------+---------------------------------+
559| Ordering | ``a > b`` | ``gt(a, b)`` |
560+-----------------------+-------------------------+---------------------------------+
561