Kaydet (Commit) e7cb1ce8 authored tarafından Georg Brandl's avatar Georg Brandl

#5310, #3558: fix operator precedence table.

üst 749e6d0a
...@@ -816,14 +816,14 @@ Raising a negative number to a fractional power results in a :exc:`ValueError`. ...@@ -816,14 +816,14 @@ Raising a negative number to a fractional power results in a :exc:`ValueError`.
.. _unary: .. _unary:
Unary arithmetic operations Unary arithmetic and bitwise operations
=========================== =======================================
.. index:: .. index::
triple: unary; arithmetic; operation triple: unary; arithmetic; operation
triple: unary; bitwise; 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:: .. productionlist::
u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr` u_expr: `power` | "-" `u_expr` | "+" `u_expr` | "~" `u_expr`
...@@ -1276,12 +1276,9 @@ groups from right to left). ...@@ -1276,12 +1276,9 @@ groups from right to left).
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| :keyword:`not` *x* | Boolean NOT | | :keyword:`not` *x* | Boolean NOT |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| :keyword:`in`, :keyword:`not` :keyword:`in` | Membership tests | | :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership |
+-----------------------------------------------+-------------------------------------+ | :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, |
| :keyword:`is`, :keyword:`is not` | Identity tests | | ``<=``, ``>``, ``>=``, ``<>``, ``!=``, ``==`` | |
+-----------------------------------------------+-------------------------------------+
| ``<``, ``<=``, ``>``, ``>=``, ``<>``, ``!=``, | Comparisons |
| ``==`` | |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| ``|`` | Bitwise OR | | ``|`` | Bitwise OR |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
...@@ -1293,29 +1290,19 @@ groups from right to left). ...@@ -1293,29 +1290,19 @@ groups from right to left).
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| ``+``, ``-`` | Addition and subtraction | | ``+``, ``-`` | Addition and subtraction |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| ``*``, ``/``, ``%`` | Multiplication, division, remainder | | ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder |
+-----------------------------------------------+-------------------------------------+
| ``+x``, ``-x`` | Positive, negative |
+-----------------------------------------------+-------------------------------------+
| ``~x`` | Bitwise not |
+-----------------------------------------------+-------------------------------------+
| ``**`` | Exponentiation |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
| ``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, |
| ``(expressions...)`` | Binding or tuple display | | ``{key:datum...}``, | dictionary display, |
+-----------------------------------------------+-------------------------------------+ | ```expressions...``` | string conversion |
| ``[expressions...]`` | List display |
+-----------------------------------------------+-------------------------------------+
| ``{key:datum...}`` | Dictionary display |
+-----------------------------------------------+-------------------------------------+
| ```expressions...``` | String conversion |
+-----------------------------------------------+-------------------------------------+ +-----------------------------------------------+-------------------------------------+
.. rubric:: Footnotes .. rubric:: Footnotes
...@@ -1358,3 +1345,6 @@ groups from right to left). ...@@ -1358,3 +1345,6 @@ groups from right to left).
descriptors, you may notice seemingly unusual behaviour in certain uses of descriptors, you may notice seemingly unusual behaviour in certain uses of
the :keyword:`is` operator, like those involving comparisons between instance the :keyword:`is` operator, like those involving comparisons between instance
methods, or constants. Check their documentation for more info. 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``.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment