From e7cb1ce8959a19ef7d07a035cc5bfe0c976fbdbf Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 19 Feb 2009 08:30:06 +0000 Subject: #5310, #3558: fix operator precedence table. --- Doc/reference/expressions.rst | 46 +++++++++++++++++-------------------------- 1 file 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``. -- cgit v0.12