diff options
author | Georg Brandl <georg@python.org> | 2009-02-19 08:30:06 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2009-02-19 08:30:06 (GMT) |
commit | e7cb1ce8959a19ef7d07a035cc5bfe0c976fbdbf (patch) | |
tree | 2bc645bdde694edf49c312157e40ebdf9f2e5d70 | |
parent | 749e6d0a01d4cbd30a2cfbd90fe332658a9284ed (diff) | |
download | cpython-e7cb1ce8959a19ef7d07a035cc5bfe0c976fbdbf.zip cpython-e7cb1ce8959a19ef7d07a035cc5bfe0c976fbdbf.tar.gz cpython-e7cb1ce8959a19ef7d07a035cc5bfe0c976fbdbf.tar.bz2 |
#5310, #3558: fix operator precedence table.
-rw-r--r-- | Doc/reference/expressions.rst | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 550644c..3664ee9 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -816,14 +816,14 @@ Raising a negative number to a fractional power results in a :exc:`ValueError`. .. _unary: -Unary arithmetic operations -=========================== +Unary arithmetic and bitwise operations +======================================= .. index:: triple: unary; arithmetic; operation triple: unary; bitwise; operation -All unary arithmetic (and bitwise) operations have the same priority: +All unary arithmetic and bitwise operations have the same priority: .. productionlist:: u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr` @@ -1276,12 +1276,9 @@ groups from right to left). +-----------------------------------------------+-------------------------------------+ | :keyword:`not` *x* | Boolean NOT | +-----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in` | Membership tests | -+-----------------------------------------------+-------------------------------------+ -| :keyword:`is`, :keyword:`is not` | Identity tests | -+-----------------------------------------------+-------------------------------------+ -| ``<``, ``<=``, ``>``, ``>=``, ``<>``, ``!=``, | Comparisons | -| ``==`` | | +| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | +| ``<=``, ``>``, ``>=``, ``<>``, ``!=``, ``==`` | | +-----------------------------------------------+-------------------------------------+ | ``|`` | Bitwise OR | +-----------------------------------------------+-------------------------------------+ @@ -1293,29 +1290,19 @@ groups from right to left). +-----------------------------------------------+-------------------------------------+ | ``+``, ``-`` | Addition and subtraction | +-----------------------------------------------+-------------------------------------+ -| ``*``, ``/``, ``%`` | Multiplication, division, remainder | -+-----------------------------------------------+-------------------------------------+ -| ``+x``, ``-x`` | Positive, negative | -+-----------------------------------------------+-------------------------------------+ -| ``~x`` | Bitwise not | -+-----------------------------------------------+-------------------------------------+ -| ``**`` | Exponentiation | +| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder | +-----------------------------------------------+-------------------------------------+ -| ``x[index]`` | Subscription | +| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT | +-----------------------------------------------+-------------------------------------+ -| ``x[index:index]`` | Slicing | +| ``**`` | Exponentiation [#]_ | +-----------------------------------------------+-------------------------------------+ -| ``x(arguments...)`` | Call | +| ``x[index]``, ``x[index:index]``, | Subscription, slicing, | +| ``x(arguments...)``, ``x.attribute`` | call, attribute reference | +-----------------------------------------------+-------------------------------------+ -| ``x.attribute`` | Attribute reference | -+-----------------------------------------------+-------------------------------------+ -| ``(expressions...)`` | Binding or tuple display | -+-----------------------------------------------+-------------------------------------+ -| ``[expressions...]`` | List display | -+-----------------------------------------------+-------------------------------------+ -| ``{key:datum...}`` | Dictionary display | -+-----------------------------------------------+-------------------------------------+ -| ```expressions...``` | String conversion | +| ``(expressions...)``, | Binding or tuple display, | +| ``[expressions...]``, | list display, | +| ``{key:datum...}``, | dictionary display, | +| ```expressions...``` | string conversion | +-----------------------------------------------+-------------------------------------+ .. rubric:: Footnotes @@ -1358,3 +1345,6 @@ groups from right to left). descriptors, you may notice seemingly unusual behaviour in certain uses of the :keyword:`is` operator, like those involving comparisons between instance methods, or constants. Check their documentation for more info. + +.. [#] The power operator ``**`` binds less tightly than an arithmetic or + bitwise unary operator on its right, that is, ``2**-1`` is ``0.5``. |