annotate Doc/library/operator.rst @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents ec634e57bc58
children f5d68604c6b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
1 :mod:`operator` --- Standard operators as functions
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
2 ===================================================
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
3
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
4 .. module:: operator
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
5 :synopsis: Functions corresponding to the standard operators.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
6 .. sectionauthor:: Skip Montanaro <skip@automatrix.com>
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
7
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
8
46027
7563f4d2f36e Make the doctests presentation-friendlier.
Georg Brandl <georg@python.org>
parents: 46012
diff changeset
9 .. testsetup::
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50065
diff changeset
10
46027
7563f4d2f36e Make the doctests presentation-friendlier.
Georg Brandl <georg@python.org>
parents: 46012
diff changeset
11 import operator
7563f4d2f36e Make the doctests presentation-friendlier.
Georg Brandl <georg@python.org>
parents: 46012
diff changeset
12 from operator import itemgetter
7563f4d2f36e Make the doctests presentation-friendlier.
Georg Brandl <georg@python.org>
parents: 46012
diff changeset
13
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
14
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
15 The :mod:`operator` module exports a set of functions implemented in C
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
16 corresponding to the intrinsic operators of Python. For example,
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
17 ``operator.add(x, y)`` is equivalent to the expression ``x+y``. The function
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
18 names are those used for special class methods; variants without leading and
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
19 trailing ``__`` are also provided for convenience.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
20
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
21 The functions fall into categories that perform object comparisons, logical
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
22 operations, mathematical operations, sequence operations, and abstract type
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
23 tests.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
24
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
25 The object comparison functions are useful for all objects, and are named after
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
26 the rich comparison operators they support:
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
27
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
28
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
29 .. function:: lt(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
30 le(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
31 eq(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
32 ne(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
33 ge(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
34 gt(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
35 __lt__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
36 __le__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
37 __eq__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
38 __ne__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
39 __ge__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
40 __gt__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
41
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
42 Perform "rich comparisons" between *a* and *b*. Specifically, ``lt(a, b)`` is
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
43 equivalent to ``a < b``, ``le(a, b)`` is equivalent to ``a <= b``, ``eq(a,
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
44 b)`` is equivalent to ``a == b``, ``ne(a, b)`` is equivalent to ``a != b``,
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
45 ``gt(a, b)`` is equivalent to ``a > b`` and ``ge(a, b)`` is equivalent to ``a
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
46 >= b``. Note that unlike the built-in :func:`cmp`, these functions can
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
47 return any value, which may or may not be interpretable as a Boolean value.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
48 See :ref:`comparisons` for more information about rich comparisons.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
49
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
50 .. versionadded:: 2.2
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
51
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
52 The logical operations are also generally applicable to all objects, and support
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
53 truth tests, identity tests, and boolean operations:
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
54
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
55
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
56 .. function:: not_(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
57 __not__(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
58
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
59 Return the outcome of :keyword:`not` *obj*. (Note that there is no
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
60 :meth:`__not__` method for object instances; only the interpreter core defines
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
61 this operation. The result is affected by the :meth:`__nonzero__` and
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
62 :meth:`__len__` methods.)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
63
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
64
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
65 .. function:: truth(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
66
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
67 Return :const:`True` if *obj* is true, and :const:`False` otherwise. This is
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
68 equivalent to using the :class:`bool` constructor.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
69
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
70
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
71 .. function:: is_(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
72
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
73 Return ``a is b``. Tests object identity.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
74
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
75 .. versionadded:: 2.3
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
76
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
77
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
78 .. function:: is_not(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
79
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
80 Return ``a is not b``. Tests object identity.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
81
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
82 .. versionadded:: 2.3
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
83
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
84 The mathematical and bitwise operations are the most numerous:
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
85
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
86
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
87 .. function:: abs(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
88 __abs__(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
89
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
90 Return the absolute value of *obj*.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
91
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
92
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
93 .. function:: add(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
94 __add__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
95
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
96 Return ``a + b``, for *a* and *b* numbers.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
97
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
98
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
99 .. function:: and_(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
100 __and__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
101
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
102 Return the bitwise and of *a* and *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
103
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
104
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
105 .. function:: div(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
106 __div__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
107
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
108 Return ``a / b`` when ``__future__.division`` is not in effect. This is
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
109 also known as "classic" division.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
110
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
111
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
112 .. function:: floordiv(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
113 __floordiv__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
114
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
115 Return ``a // b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
116
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
117 .. versionadded:: 2.2
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
118
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
119
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
120 .. function:: inv(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
121 invert(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
122 __inv__(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
123 __invert__(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
124
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
125 Return the bitwise inverse of the number *obj*. This is equivalent to ``~obj``.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
126
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
127 .. versionadded:: 2.0
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
128 The names :func:`invert` and :func:`__invert__`.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
129
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
130
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
131 .. function:: lshift(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
132 __lshift__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
133
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
134 Return *a* shifted left by *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
135
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
136
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
137 .. function:: mod(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
138 __mod__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
139
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
140 Return ``a % b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
141
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
142
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
143 .. function:: mul(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
144 __mul__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
145
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
146 Return ``a * b``, for *a* and *b* numbers.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
147
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
148
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
149 .. function:: neg(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
150 __neg__(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
151
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
152 Return *obj* negated.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
153
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
154
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
155 .. function:: or_(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
156 __or__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
157
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
158 Return the bitwise or of *a* and *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
159
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
160
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
161 .. function:: pos(obj)
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
162 __pos__(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
163
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
164 Return *obj* positive.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
165
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
166
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
167 .. function:: pow(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
168 __pow__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
169
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
170 Return ``a ** b``, for *a* and *b* numbers.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
171
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
172 .. versionadded:: 2.3
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
173
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
174
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
175 .. function:: rshift(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
176 __rshift__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
177
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
178 Return *a* shifted right by *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
179
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
180
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
181 .. function:: sub(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
182 __sub__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
183
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
184 Return ``a - b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
185
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
186
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
187 .. function:: truediv(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
188 __truediv__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
189
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
190 Return ``a / b`` when ``__future__.division`` is in effect. This is also
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
191 known as "true" division.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
192
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
193 .. versionadded:: 2.2
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
194
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
195
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
196 .. function:: xor(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
197 __xor__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
198
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
199 Return the bitwise exclusive or of *a* and *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
200
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
201
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
202 .. function:: index(a)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
203 __index__(a)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
204
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
205 Return *a* converted to an integer. Equivalent to ``a.__index__()``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
206
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
207 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
208
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
209
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
210 Operations which work with sequences include:
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
211
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
212 .. function:: concat(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
213 __concat__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
214
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
215 Return ``a + b`` for *a* and *b* sequences.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
216
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
217
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
218 .. function:: contains(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
219 __contains__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
220
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
221 Return the outcome of the test ``b in a``. Note the reversed operands.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
222
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
223 .. versionadded:: 2.0
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
224 The name :func:`__contains__`.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
225
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
226
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
227 .. function:: countOf(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
228
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
229 Return the number of occurrences of *b* in *a*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
230
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
231
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
232 .. function:: delitem(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
233 __delitem__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
234
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
235 Remove the value of *a* at index *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
236
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
237
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
238 .. function:: delslice(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
239 __delslice__(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
240
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
241 Delete the slice of *a* from index *b* to index *c-1*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
242
50065
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
243 .. deprecated:: 2.6
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
244 This function is removed in Python 3.x. Use :func:`delitem` with a slice
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
245 index.
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
246
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
247
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
248 .. function:: getitem(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
249 __getitem__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
250
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
251 Return the value of *a* at index *b*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
252
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
253
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
254 .. function:: getslice(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
255 __getslice__(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
256
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
257 Return the slice of *a* from index *b* to index *c-1*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
258
50065
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
259 .. deprecated:: 2.6
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
260 This function is removed in Python 3.x. Use :func:`getitem` with a slice
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
261 index.
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
262
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
263
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
264 .. function:: indexOf(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
265
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
266 Return the index of the first of occurrence of *b* in *a*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
267
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
268
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
269 .. function:: repeat(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
270 __repeat__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
271
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
272 .. deprecated:: 2.7
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
273 Use :func:`__mul__` instead.
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
274
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
275 Return ``a * b`` where *a* is a sequence and *b* is an integer.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
276
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
277
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
278 .. function:: sequenceIncludes(...)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
279
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
280 .. deprecated:: 2.0
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
281 Use :func:`contains` instead.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
282
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
283 Alias for :func:`contains`.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
284
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
285
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
286 .. function:: setitem(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
287 __setitem__(a, b, c)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
288
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
289 Set the value of *a* at index *b* to *c*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
290
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
291
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
292 .. function:: setslice(a, b, c, v)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
293 __setslice__(a, b, c, v)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
294
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
295 Set the slice of *a* from index *b* to index *c-1* to the sequence *v*.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
296
50065
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
297 .. deprecated:: 2.6
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
298 This function is removed in Python 3.x. Use :func:`setitem` with a slice
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
299 index.
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
300
51313
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
301 Example use of operator functions::
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
302
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
303 >>> # Elementwise multiplication
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
304 >>> map(mul, [0, 1, 2, 3], [10, 20, 30, 40])
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
305 [0, 20, 60, 120]
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
306
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
307 >>> # Dot product
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
308 >>> sum(map(mul, [0, 1, 2, 3], [10, 20, 30, 40]))
ec634e57bc58 Doc fixes. Remove overbroad, redundant warnings. Fixup example code.
Raymond Hettinger <python@rcn.com>
parents: 51291
diff changeset
309 200
50065
ae98681058b2 Merged revisions 67571,67574-67576,67579-67581,67583,67591,67597,67608,67631 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47937
diff changeset
310
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
311 Many operations have an "in-place" version. The following functions provide a
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
312 more primitive access to in-place operators than the usual syntax does; for
44103
1e266015cf5b Add more entries to the glossary.
Georg Brandl <georg@python.org>
parents: 43359
diff changeset
313 example, the :term:`statement` ``x += y`` is equivalent to
1e266015cf5b Add more entries to the glossary.
Georg Brandl <georg@python.org>
parents: 43359
diff changeset
314 ``x = operator.iadd(x, y)``. Another way to put it is to say that
1e266015cf5b Add more entries to the glossary.
Georg Brandl <georg@python.org>
parents: 43359
diff changeset
315 ``z = operator.iadd(x, y)`` is equivalent to the compound statement
1e266015cf5b Add more entries to the glossary.
Georg Brandl <georg@python.org>
parents: 43359
diff changeset
316 ``z = x; z += y``.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
317
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
318 .. function:: iadd(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
319 __iadd__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
320
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
321 ``a = iadd(a, b)`` is equivalent to ``a += b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
322
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
323 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
324
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
325
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
326 .. function:: iand(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
327 __iand__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
328
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
329 ``a = iand(a, b)`` is equivalent to ``a &= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
330
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
331 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
332
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
333
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
334 .. function:: iconcat(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
335 __iconcat__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
336
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
337 ``a = iconcat(a, b)`` is equivalent to ``a += b`` for *a* and *b* sequences.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
338
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
339 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
340
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
341
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
342 .. function:: idiv(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
343 __idiv__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
344
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
345 ``a = idiv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division`` is
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
346 not in effect.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
347
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
348 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
349
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
350
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
351 .. function:: ifloordiv(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
352 __ifloordiv__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
353
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
354 ``a = ifloordiv(a, b)`` is equivalent to ``a //= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
355
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
356 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
357
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
358
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
359 .. function:: ilshift(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
360 __ilshift__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
361
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
362 ``a = ilshift(a, b)`` is equivalent to ``a <``\ ``<= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
363
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
364 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
365
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
366
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
367 .. function:: imod(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
368 __imod__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
369
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
370 ``a = imod(a, b)`` is equivalent to ``a %= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
371
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
372 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
373
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
374
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
375 .. function:: imul(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
376 __imul__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
377
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
378 ``a = imul(a, b)`` is equivalent to ``a *= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
379
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
380 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
381
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
382
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
383 .. function:: ior(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
384 __ior__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
385
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
386 ``a = ior(a, b)`` is equivalent to ``a |= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
387
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
388 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
389
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
390
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
391 .. function:: ipow(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
392 __ipow__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
393
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
394 ``a = ipow(a, b)`` is equivalent to ``a **= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
395
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
396 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
397
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
398
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
399 .. function:: irepeat(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
400 __irepeat__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
401
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
402 .. deprecated:: 2.7
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
403 Use :func:`__imul__` instead.
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
404
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
405 ``a = irepeat(a, b)`` is equivalent to ``a *= b`` where *a* is a sequence and
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
406 *b* is an integer.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
407
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
408 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
409
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
410
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
411 .. function:: irshift(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
412 __irshift__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
413
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
414 ``a = irshift(a, b)`` is equivalent to ``a >>= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
415
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
416 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
417
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
418
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
419 .. function:: isub(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
420 __isub__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
421
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
422 ``a = isub(a, b)`` is equivalent to ``a -= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
423
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
424 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
425
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
426
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
427 .. function:: itruediv(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
428 __itruediv__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
429
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
430 ``a = itruediv(a, b)`` is equivalent to ``a /= b`` when ``__future__.division``
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
431 is in effect.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
432
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
433 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
434
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
435
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
436 .. function:: ixor(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
437 __ixor__(a, b)
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
438
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
439 ``a = ixor(a, b)`` is equivalent to ``a ^= b``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
440
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
441 .. versionadded:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
442
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
443
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
444 The :mod:`operator` module also defines a few predicates to test the type of
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
445 objects; however, these are not all reliable. It is preferable to test
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
446 abstract base classes instead (see :mod:`collections` and
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
447 :mod:`numbers` for details).
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
448
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
449 .. function:: isCallable(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
450
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
451 .. deprecated:: 2.0
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
452 Use ``isinstance(x, collections.Callable)`` instead.
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
453
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
454 Returns true if the object *obj* can be called like a function, otherwise it
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
455 returns false. True is returned for functions, bound and unbound methods, class
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
456 objects, and instance objects which support the :meth:`__call__` method.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
457
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
458
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
459 .. function:: isMappingType(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
460
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
461 .. deprecated:: 2.7
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
462 Use ``isinstance(x, collections.Mapping)`` instead.
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
463
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
464 Returns true if the object *obj* supports the mapping interface. This is true for
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
465 dictionaries and all instance objects defining :meth:`__getitem__`.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
466
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
467
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
468 .. function:: isNumberType(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
469
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
470 .. deprecated:: 2.7
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
471 Use ``isinstance(x, numbers.Number)`` instead.
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
472
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
473 Returns true if the object *obj* represents a number. This is true for all
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
474 numeric types implemented in C.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
475
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
476
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
477 .. function:: isSequenceType(obj)
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
478
51291
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
479 .. deprecated:: 2.7
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
480 Use ``isinstance(x, collections.Sequence)`` instead.
7354f1afaecb Record operator deprecations in docs.
Raymond Hettinger <python@rcn.com>
parents: 50522
diff changeset
481
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
482 Returns true if the object *obj* supports the sequence protocol. This returns true
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
483 for all objects which define sequence methods in C, and for all instance objects
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
484 defining :meth:`__getitem__`.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
485
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
486
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
487 The :mod:`operator` module also defines tools for generalized attribute and item
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
488 lookups. These are useful for making fast field extractors as arguments for
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
489 :func:`map`, :func:`sorted`, :meth:`itertools.groupby`, or other functions that
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
490 expect a function argument.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
491
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
492
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
493 .. function:: attrgetter(attr[, args...])
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
494
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
495 Return a callable object that fetches *attr* from its operand. If more than one
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
496 attribute is requested, returns a tuple of attributes. After,
45487
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
497 ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After,
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
498 ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name,
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
499 b.date)``.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
500
45487
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
501 The attribute names can also contain dots; after ``f = attrgetter('date.month')``,
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
502 the call ``f(b)`` returns ``b.date.month``.
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
503
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
504 .. versionadded:: 2.4
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
505
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
506 .. versionchanged:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
507 Added support for multiple attributes.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
508
45487
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
509 .. versionchanged:: 2.6
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
510 Added support for dotted attributes.
813c146858f7 #1826: allow dotted attribute paths in operator.attrgetter.
Georg Brandl <georg@python.org>
parents: 44103
diff changeset
511
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
512
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
513 .. function:: itemgetter(item[, args...])
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
514
45732
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
515 Return a callable object that fetches *item* from its operand using the
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
516 operand's :meth:`__getitem__` method. If multiple items are specified,
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
517 returns a tuple of lookup values. Equivalent to::
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
518
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
519 def itemgetter(*items):
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
520 if len(items) == 1:
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
521 item = items[0]
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
522 def g(obj):
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
523 return obj[item]
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
524 else:
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
525 def g(obj):
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
526 return tuple(obj[item] for item in items)
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
527 return g
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50065
diff changeset
528
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50065
diff changeset
529 The items can be any type accepted by the operand's :meth:`__getitem__`
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50065
diff changeset
530 method. Dictionaries accept any hashable value. Lists, tuples, and
46012
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
531 strings accept an index or a slice:
45732
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
532
46012
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
533 >>> itemgetter(1)('ABCDEFG')
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
534 'B'
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
535 >>> itemgetter(1,3,5)('ABCDEFG')
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
536 ('B', 'D', 'F')
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
537 >>> itemgetter(slice(2,None))('ABCDEFG')
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
538 'CDEFG'
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
539
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
540 .. versionadded:: 2.4
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
541
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
542 .. versionchanged:: 2.5
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
543 Added support for multiple item extraction.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
544
45732
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
545 Example of using :func:`itemgetter` to retrieve specific fields from a
46012
2e5ab35ccaf1 Test doctests in operator docs.
Georg Brandl <georg@python.org>
parents: 45732
diff changeset
546 tuple record:
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
547
45732
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
548 >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)]
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
549 >>> getcount = itemgetter(1)
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
550 >>> map(getcount, inventory)
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
551 [3, 2, 5, 1]
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
552 >>> sorted(inventory, key=getcount)
ce5f6fd57913 Improve docs for itemgetter(). Show that it works with slices.
Raymond Hettinger <python@rcn.com>
parents: 45488
diff changeset
553 [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
554
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
555
45488
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
556 .. function:: methodcaller(name[, args...])
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
557
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
558 Return a callable object that calls the method *name* on its operand. If
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
559 additional arguments and/or keyword arguments are given, they will be given
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
560 to the method as well. After ``f = methodcaller('name')``, the call ``f(b)``
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
561 returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
562 call ``f(b)`` returns ``b.name('foo', bar=1)``.
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
563
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
564 .. versionadded:: 2.6
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
565
c126bd9b505b #1506171: added operator.methodcaller().
Georg Brandl <georg@python.org>
parents: 45487
diff changeset
566
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
567 .. _operator-map:
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
568
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
569 Mapping Operators to Functions
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
570 ------------------------------
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
571
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
572 This table shows how abstract operations correspond to operator symbols in the
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
573 Python syntax and the functions in the :mod:`operator` module.
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
574
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
575 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
576 | Operation | Syntax | Function |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
577 +=======================+=========================+=================================+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
578 | Addition | ``a + b`` | ``add(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
579 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
580 | Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
581 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
582 | Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
583 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
584 | Division | ``a / b`` | ``div(a, b)`` (without |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
585 | | | ``__future__.division``) |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
586 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
587 | Division | ``a / b`` | ``truediv(a, b)`` (with |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
588 | | | ``__future__.division``) |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
589 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
590 | Division | ``a // b`` | ``floordiv(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
591 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
592 | Bitwise And | ``a & b`` | ``and_(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
593 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
594 | Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
595 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
596 | Bitwise Inversion | ``~ a`` | ``invert(a)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
597 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
598 | Bitwise Or | ``a | b`` | ``or_(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
599 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
600 | Exponentiation | ``a ** b`` | ``pow(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
601 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
602 | Identity | ``a is b`` | ``is_(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
603 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
604 | Identity | ``a is not b`` | ``is_not(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
605 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
606 | Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
607 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
608 | Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
609 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
610 | Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
611 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
612 | Left Shift | ``a << b`` | ``lshift(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
613 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
614 | Modulo | ``a % b`` | ``mod(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
615 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
616 | Multiplication | ``a * b`` | ``mul(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
617 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
618 | Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
619 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
620 | Negation (Logical) | ``not a`` | ``not_(a)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
621 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
622 | Right Shift | ``a >> b`` | ``rshift(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
623 +-----------------------+-------------------------+---------------------------------+
47937
38d3a50defec fix various doc typos #3320
Benjamin Peterson <benjamin@python.org>
parents: 46027
diff changeset
624 | Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
625 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
626 | Slice Assignment | ``seq[i:j] = values`` | ``setslice(seq, i, j, values)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
627 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
628 | Slice Deletion | ``del seq[i:j]`` | ``delslice(seq, i, j)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
629 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
630 | Slicing | ``seq[i:j]`` | ``getslice(seq, i, j)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
631 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
632 | String Formatting | ``s % obj`` | ``mod(s, obj)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
633 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
634 | Subtraction | ``a - b`` | ``sub(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
635 +-----------------------+-------------------------+---------------------------------+
43359
c79a2f0a7034 Replaced variable o with obj in operator.rst because o is easy to
Mark Summerfield <list@qtrac.plus.com>
parents: 42603
diff changeset
636 | Truth Test | ``obj`` | ``truth(obj)`` |
42603
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
637 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
638 | Ordering | ``a < b`` | ``lt(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
639 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
640 | Ordering | ``a <= b`` | ``le(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
641 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
642 | Equality | ``a == b`` | ``eq(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
643 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
644 | Difference | ``a != b`` | ``ne(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
645 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
646 | Ordering | ``a >= b`` | ``ge(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
647 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
648 | Ordering | ``a > b`` | ``gt(a, b)`` |
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
649 +-----------------------+-------------------------+---------------------------------+
c62f6669ae22 Move the 2.6 reST doc tree in place.
Georg Brandl <georg@python.org>
parents:
diff changeset
650