summaryrefslogtreecommitdiffstats
path: root/Doc/library/operator.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/operator.rst')
-rw-r--r--Doc/library/operator.rst156
1 files changed, 84 insertions, 72 deletions
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst
index 24ace8b..175314e 100644
--- a/Doc/library/operator.rst
+++ b/Doc/library/operator.rst
@@ -104,6 +104,14 @@ The mathematical and bitwise operations are the most numerous:
Return ``a // b``.
+.. function:: index(a)
+ __index__(a)
+
+ Return *a* converted to an integer. Equivalent to ``a.__index__()``.
+
+ .. versionadded:: 2.5
+
+
.. function:: inv(obj)
invert(obj)
__inv__(obj)
@@ -133,7 +141,7 @@ The mathematical and bitwise operations are the most numerous:
.. function:: neg(obj)
__neg__(obj)
- Return *obj* negated.
+ Return *obj* negated (``-obj``).
.. function:: or_(a, b)
@@ -145,7 +153,7 @@ The mathematical and bitwise operations are the most numerous:
.. function:: pos(obj)
__pos__(obj)
- Return *obj* positive.
+ Return *obj* positive (``+obj``).
.. function:: pow(a, b)
@@ -179,13 +187,7 @@ The mathematical and bitwise operations are the most numerous:
Return the bitwise exclusive or of *a* and *b*.
-.. function:: index(a)
- __index__(a)
-
- Return *a* converted to an integer. Equivalent to ``a.__index__()``.
-
-
-Operations which work with sequences include:
+Operations which work with sequences (some of them with mappings too) include:
.. function:: concat(a, b)
__concat__(a, b)
@@ -394,67 +396,77 @@ Mapping Operators to Functions
This table shows how abstract operations correspond to operator symbols in the
Python syntax and the functions in the :mod:`operator` module.
-+-----------------------+-------------------------+---------------------------------+
-| Operation | Syntax | Function |
-+=======================+=========================+=================================+
-| Addition | ``a + b`` | ``add(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Division | ``a / b`` | ``truediv(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Division | ``a // b`` | ``floordiv(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Bitwise And | ``a & b`` | ``and_(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Identity | ``a is b`` | ``is_(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Identity | ``a is not b`` | ``is_not(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Left Shift | ``a << b`` | ``lshift(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Modulo | ``a % b`` | ``mod(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Multiplication | ``a * b`` | ``mul(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Negation (Logical) | ``not a`` | ``not_(a)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Subtraction | ``a - b`` | ``sub(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Truth Test | ``obj`` | ``truth(obj)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Ordering | ``a < b`` | ``lt(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Ordering | ``a <= b`` | ``le(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Equality | ``a == b`` | ``eq(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Difference | ``a != b`` | ``ne(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Ordering | ``a >= b`` | ``ge(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
-| Ordering | ``a > b`` | ``gt(a, b)`` |
-+-----------------------+-------------------------+---------------------------------+
++-----------------------+-------------------------+---------------------------------------+
+| Operation | Syntax | Function |
++=======================+=========================+=======================================+
+| Addition | ``a + b`` | ``add(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Concatenation | ``seq1 + seq2`` | ``concat(seq1, seq2)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Containment Test | ``obj in seq`` | ``contains(seq, obj)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Division | ``a / b`` | ``div(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Division | ``a // b`` | ``floordiv(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Bitwise And | ``a & b`` | ``and_(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Bitwise Exclusive Or | ``a ^ b`` | ``xor(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Bitwise Inversion | ``~ a`` | ``invert(a)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Bitwise Or | ``a | b`` | ``or_(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Exponentiation | ``a ** b`` | ``pow(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Identity | ``a is b`` | ``is_(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Identity | ``a is not b`` | ``is_not(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Indexed Assignment | ``obj[k] = v`` | ``setitem(obj, k, v)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Indexed Deletion | ``del obj[k]`` | ``delitem(obj, k)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Indexing | ``obj[k]`` | ``getitem(obj, k)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Left Shift | ``a << b`` | ``lshift(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Modulo | ``a % b`` | ``mod(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Multiplication | ``a * b`` | ``mul(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Negation (Arithmetic) | ``- a`` | ``neg(a)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Negation (Logical) | ``not a`` | ``not_(a)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Positive | ``+ a`` | ``pos(a)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Right Shift | ``a >> b`` | ``rshift(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Sequence Repetition | ``seq * i`` | ``repeat(seq, i)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Slice Assignment | ``seq[i:j] = values`` | ``setitem(seq, slice(i, j), values)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Slice Deletion | ``del seq[i:j]`` | ``delitem(seq, slice(i, j))`` |
++-----------------------+-------------------------+---------------------------------------+
+| Slicing | ``seq[i:j]`` | ``getitem(seq, slice(i, j))`` |
++-----------------------+-------------------------+---------------------------------------+
+| String Formatting | ``s % obj`` | ``mod(s, obj)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Subtraction | ``a - b`` | ``sub(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Truth Test | ``obj`` | ``truth(obj)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Ordering | ``a < b`` | ``lt(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Ordering | ``a <= b`` | ``le(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Equality | ``a == b`` | ``eq(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Difference | ``a != b`` | ``ne(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Ordering | ``a >= b`` | ``ge(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+
+| Ordering | ``a > b`` | ``gt(a, b)`` |
++-----------------------+-------------------------+---------------------------------------+