blob: d1d1c168ad91065b1e07cd0bf04f8248b57c2323 [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
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 Brandl48310cd2009-01-03 21:18:54 +0000212
Georg Brandl116aa622007-08-15 14:28:22 +0000213.. function:: getitem(a, b)
214 __getitem__(a, b)
215
216 Return the value of *a* at index *b*.
217
218
Georg Brandl116aa622007-08-15 14:28:22 +0000219.. function:: indexOf(a, b)
220
221 Return the index of the first of occurrence of *b* in *a*.
222
223
224.. function:: repeat(a, b)
225 __repeat__(a, b)
226
227 Return ``a * b`` where *a* is a sequence and *b* is an integer.
228
229
Georg Brandl116aa622007-08-15 14:28:22 +0000230.. function:: setitem(a, b, c)
231 __setitem__(a, b, c)
232
233 Set the value of *a* at index *b* to *c*.
234
235
Georg Brandl116aa622007-08-15 14:28:22 +0000236Many operations have an "in-place" version. The following functions provide a
237more primitive access to in-place operators than the usual syntax does; for
Christian Heimesd8654cf2007-12-02 15:22:16 +0000238example, the :term:`statement` ``x += y`` is equivalent to
239``x = operator.iadd(x, y)``. Another way to put it is to say that
240``z = operator.iadd(x, y)`` is equivalent to the compound statement
241``z = x; z += y``.
Georg Brandl116aa622007-08-15 14:28:22 +0000242
243.. function:: iadd(a, b)
244 __iadd__(a, b)
245
246 ``a = iadd(a, b)`` is equivalent to ``a += b``.
247
Georg Brandl116aa622007-08-15 14:28:22 +0000248
249.. function:: iand(a, b)
250 __iand__(a, b)
251
252 ``a = iand(a, b)`` is equivalent to ``a &= b``.
253
Georg Brandl116aa622007-08-15 14:28:22 +0000254
255.. function:: iconcat(a, b)
256 __iconcat__(a, b)
257
258 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
259
Georg Brandl116aa622007-08-15 14:28:22 +0000260
Georg Brandl116aa622007-08-15 14:28:22 +0000261.. function:: ifloordiv(a, b)
262 __ifloordiv__(a, b)
263
264 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
265
Georg Brandl116aa622007-08-15 14:28:22 +0000266
267.. function:: ilshift(a, b)
268 __ilshift__(a, b)
269
Georg Brandl55ac8f02007-09-01 13:51:09 +0000270 ``a = ilshift(a, b)`` is equivalent to ``a <<= b``.
Georg Brandl116aa622007-08-15 14:28:22 +0000271
272
273.. function:: imod(a, b)
274 __imod__(a, b)
275
276 ``a = imod(a, b)`` is equivalent to ``a %= b``.
277
Georg Brandl116aa622007-08-15 14:28:22 +0000278
279.. function:: imul(a, b)
280 __imul__(a, b)
281
282 ``a = imul(a, b)`` is equivalent to ``a *= b``.
283
Georg Brandl116aa622007-08-15 14:28:22 +0000284
285.. function:: ior(a, b)
286 __ior__(a, b)
287
288 ``a = ior(a, b)`` is equivalent to ``a |= b``.
289
Georg Brandl116aa622007-08-15 14:28:22 +0000290
291.. function:: ipow(a, b)
292 __ipow__(a, b)
293
294 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
295
Georg Brandl116aa622007-08-15 14:28:22 +0000296
297.. function:: irepeat(a, b)
298 __irepeat__(a, b)
299
300 ``a = irepeat(a, b)`` is equivalent to ``a *= b`` where *a* is a sequence and
301 *b* is an integer.
302
Georg Brandl116aa622007-08-15 14:28:22 +0000303
304.. function:: irshift(a, b)
305 __irshift__(a, b)
306
307 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
308
Georg Brandl116aa622007-08-15 14:28:22 +0000309
310.. function:: isub(a, b)
311 __isub__(a, b)
312
313 ``a = isub(a, b)`` is equivalent to ``a -= b``.
314
Georg Brandl116aa622007-08-15 14:28:22 +0000315
316.. function:: itruediv(a, b)
317 __itruediv__(a, b)
318
Georg Brandlf6945182008-02-01 11:56:49 +0000319 ``a = itruediv(a, b)`` is equivalent to ``a /= b``.
Georg Brandl116aa622007-08-15 14:28:22 +0000320
Georg Brandl116aa622007-08-15 14:28:22 +0000321
322.. function:: ixor(a, b)
323 __ixor__(a, b)
324
325 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.
326
Georg Brandl116aa622007-08-15 14:28:22 +0000327
328The :mod:`operator` module also defines a few predicates to test the type of
329objects.
330
Georg Brandlf6945182008-02-01 11:56:49 +0000331.. XXX just remove them?
Georg Brandl116aa622007-08-15 14:28:22 +0000332.. note::
333
Georg Brandlf6945182008-02-01 11:56:49 +0000334 Be careful not to misinterpret the results of these functions; none have any
335 measure of reliability with instance objects.
Christian Heimesfe337bf2008-03-23 21:54:12 +0000336 For example:
Georg Brandl116aa622007-08-15 14:28:22 +0000337
338 >>> class C:
339 ... pass
Georg Brandl48310cd2009-01-03 21:18:54 +0000340 ...
Georg Brandl116aa622007-08-15 14:28:22 +0000341 >>> import operator
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000342 >>> obj = C()
343 >>> operator.isMappingType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000344 True
345
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000346.. note::
Georg Brandl116aa622007-08-15 14:28:22 +0000347
Georg Brandlf6945182008-02-01 11:56:49 +0000348 Since there are now abstract classes for collection types, you should write,
349 for example, ``isinstance(obj, collections.Mapping)`` and ``isinstance(obj,
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000350 collections.Sequence)``.
351
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000352.. function:: isMappingType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000353
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000354 Returns true if the object *obj* supports the mapping interface. This is true for
Georg Brandl116aa622007-08-15 14:28:22 +0000355 dictionaries and all instance objects defining :meth:`__getitem__`.
356
357 .. warning::
358
359 There is no reliable way to test if an instance supports the complete mapping
360 protocol since the interface itself is ill-defined. This makes this test less
361 useful than it otherwise might be.
362
363
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000364.. function:: isNumberType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000365
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000366 Returns true if the object *obj* represents a number. This is true for all
Georg Brandl116aa622007-08-15 14:28:22 +0000367 numeric types implemented in C.
368
369 .. warning::
370
371 There is no reliable way to test if an instance supports the complete numeric
372 interface since the interface itself is ill-defined. This makes this test less
373 useful than it otherwise might be.
374
375
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000376.. function:: isSequenceType(obj)
Georg Brandl116aa622007-08-15 14:28:22 +0000377
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000378 Returns true if the object *obj* supports the sequence protocol. This returns true
Georg Brandl116aa622007-08-15 14:28:22 +0000379 for all objects which define sequence methods in C, and for all instance objects
380 defining :meth:`__getitem__`.
381
382 .. warning::
383
384 There is no reliable way to test if an instance supports the complete sequence
385 interface since the interface itself is ill-defined. This makes this test less
386 useful than it otherwise might be.
387
388Example: Build a dictionary that maps the ordinals from ``0`` to ``255`` to
Christian Heimesfe337bf2008-03-23 21:54:12 +0000389their character equivalents.
Georg Brandl116aa622007-08-15 14:28:22 +0000390
Georg Brandl116aa622007-08-15 14:28:22 +0000391 >>> d = {}
392 >>> keys = range(256)
393 >>> vals = map(chr, keys)
Christian Heimesfe337bf2008-03-23 21:54:12 +0000394 >>> map(operator.setitem, [d]*len(keys), keys, vals) # doctest: +SKIP
Georg Brandl116aa622007-08-15 14:28:22 +0000395
396.. XXX: find a better, readable, example
397
398The :mod:`operator` module also defines tools for generalized attribute and item
399lookups. These are useful for making fast field extractors as arguments for
400:func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
401expect a function argument.
402
403
404.. function:: attrgetter(attr[, args...])
405
406 Return a callable object that fetches *attr* from its operand. If more than one
407 attribute is requested, returns a tuple of attributes. After,
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000408 ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After,
409 ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name,
Georg Brandl116aa622007-08-15 14:28:22 +0000410 b.date)``.
411
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000412 The attribute names can also contain dots; after ``f = attrgetter('date.month')``,
413 the call ``f(b)`` returns ``b.date.month``.
Georg Brandl116aa622007-08-15 14:28:22 +0000414
415.. function:: itemgetter(item[, args...])
416
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000417 Return a callable object that fetches *item* from its operand using the
418 operand's :meth:`__getitem__` method. If multiple items are specified,
419 returns a tuple of lookup values. Equivalent to::
Georg Brandl116aa622007-08-15 14:28:22 +0000420
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000421 def itemgetter(*items):
422 if len(items) == 1:
423 item = items[0]
424 def g(obj):
425 return obj[item]
426 else:
427 def g(obj):
428 return tuple(obj[item] for item in items)
429 return g
Georg Brandl48310cd2009-01-03 21:18:54 +0000430
431 The items can be any type accepted by the operand's :meth:`__getitem__`
432 method. Dictionaries accept any hashable value. Lists, tuples, and
Christian Heimesfe337bf2008-03-23 21:54:12 +0000433 strings accept an index or a slice:
Georg Brandl116aa622007-08-15 14:28:22 +0000434
Christian Heimesfe337bf2008-03-23 21:54:12 +0000435 >>> itemgetter(1)('ABCDEFG')
436 'B'
437 >>> itemgetter(1,3,5)('ABCDEFG')
438 ('B', 'D', 'F')
439 >>> itemgetter(slice(2,None))('ABCDEFG')
440 'CDEFG'
Georg Brandl116aa622007-08-15 14:28:22 +0000441
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000442
443 Example of using :func:`itemgetter` to retrieve specific fields from a
Christian Heimesfe337bf2008-03-23 21:54:12 +0000444 tuple record:
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000445
Christian Heimesdd15f6c2008-03-16 00:07:10 +0000446 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
447 >>> getcount = itemgetter(1)
448 >>> map(getcount, inventory)
449 [3, 2, 5, 1]
450 >>> sorted(inventory, key=getcount)
451 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
Georg Brandl116aa622007-08-15 14:28:22 +0000452
453
Christian Heimesd3eb5a152008-02-24 00:38:49 +0000454.. function:: methodcaller(name[, args...])
455
456 Return a callable object that calls the method *name* on its operand. If
457 additional arguments and/or keyword arguments are given, they will be given
458 to the method as well. After ``f = methodcaller('name')``, the call ``f(b)``
459 returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the
460 call ``f(b)`` returns ``b.name('foo', bar=1)``.
461
462
Georg Brandl116aa622007-08-15 14:28:22 +0000463.. _operator-map:
464
465Mapping Operators to Functions
466------------------------------
467
468This table shows how abstract operations correspond to operator symbols in the
469Python syntax and the functions in the :mod:`operator` module.
470
471+-----------------------+-------------------------+---------------------------------+
472| Operation | Syntax | Function |
473+=======================+=========================+=================================+
474| Addition | ``a + b`` | ``add(a, b)`` |
475+-----------------------+-------------------------+---------------------------------+
476| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
477+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000478| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000479+-----------------------+-------------------------+---------------------------------+
Georg Brandlf6945182008-02-01 11:56:49 +0000480| Division | ``a / b`` | ``truediv(a, b)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000481+-----------------------+-------------------------+---------------------------------+
482| Division | ``a // b`` | ``floordiv(a, b)`` |
483+-----------------------+-------------------------+---------------------------------+
484| Bitwise And | ``a & b`` | ``and_(a, b)`` |
485+-----------------------+-------------------------+---------------------------------+
486| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
487+-----------------------+-------------------------+---------------------------------+
488| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
489+-----------------------+-------------------------+---------------------------------+
490| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
491+-----------------------+-------------------------+---------------------------------+
492| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
493+-----------------------+-------------------------+---------------------------------+
494| Identity | ``a is b`` | ``is_(a, b)`` |
495+-----------------------+-------------------------+---------------------------------+
496| Identity | ``a is not b`` | ``is_not(a, b)`` |
497+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000498| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000499+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000500| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000501+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000502| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000503+-----------------------+-------------------------+---------------------------------+
504| Left Shift | ``a << b`` | ``lshift(a, b)`` |
505+-----------------------+-------------------------+---------------------------------+
506| Modulo | ``a % b`` | ``mod(a, b)`` |
507+-----------------------+-------------------------+---------------------------------+
508| Multiplication | ``a * b`` | ``mul(a, b)`` |
509+-----------------------+-------------------------+---------------------------------+
510| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
511+-----------------------+-------------------------+---------------------------------+
512| Negation (Logical) | ``not a`` | ``not_(a)`` |
513+-----------------------+-------------------------+---------------------------------+
514| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
515+-----------------------+-------------------------+---------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000516| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000517+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000518| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000519+-----------------------+-------------------------+---------------------------------+
520| Subtraction | ``a - b`` | ``sub(a, b)`` |
521+-----------------------+-------------------------+---------------------------------+
Thomas Wouters1b7f8912007-09-19 03:06:30 +0000522| Truth Test | ``obj`` | ``truth(obj)`` |
Georg Brandl116aa622007-08-15 14:28:22 +0000523+-----------------------+-------------------------+---------------------------------+
524| Ordering | ``a < b`` | ``lt(a, b)`` |
525+-----------------------+-------------------------+---------------------------------+
526| Ordering | ``a <= b`` | ``le(a, b)`` |
527+-----------------------+-------------------------+---------------------------------+
528| Equality | ``a == b`` | ``eq(a, b)`` |
529+-----------------------+-------------------------+---------------------------------+
530| Difference | ``a != b`` | ``ne(a, b)`` |
531+-----------------------+-------------------------+---------------------------------+
532| Ordering | ``a >= b`` | ``ge(a, b)`` |
533+-----------------------+-------------------------+---------------------------------+
534| Ordering | ``a > b`` | ``gt(a, b)`` |
535+-----------------------+-------------------------+---------------------------------+
536