Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1783,8 +1783,8 @@ Operator precedence
.. index::
pair: operator; precedence

The following table summarizes the operator precedence in Python, from lowest
precedence (least binding) to highest precedence (most binding). Operators in
The following table summarizes the operator precedence in Python, from highest
precedence (most binding) to lowest precedence (least binding). Operators in
the same box have the same precedence. Unless the syntax is explicitly given,
operators are binary. Operators in the same box group left to right (except for
exponentiation, which groups from right to left).
Expand All @@ -1797,50 +1797,50 @@ precedence and have a left-to-right chaining feature as described in the
+-----------------------------------------------+-------------------------------------+
| Operator | Description |
+===============================================+=====================================+
| ``:=`` | Assignment expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`lambda` | Lambda expression |
| ``(expressions...)``, | Binding or parenthesized |
| | expression, |
| ``[expressions...]``, | list display, |
| ``{key: value...}``, | dictionary display, |
| ``{expressions...}`` | set display |
+-----------------------------------------------+-------------------------------------+
| :keyword:`if <if_expr>` -- :keyword:`!else` | Conditional expression |
| ``x[index]``, ``x[index:index]``, | Subscription, slicing, |
| ``x(arguments...)``, ``x.attribute`` | call, attribute reference |
+-----------------------------------------------+-------------------------------------+
| :keyword:`or` | Boolean OR |
| :keyword:`await` ``x`` | Await expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`and` | Boolean AND |
| ``**`` | Exponentiation [#]_ |
+-----------------------------------------------+-------------------------------------+
| :keyword:`not` ``x`` | Boolean NOT |
| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |
+-----------------------------------------------+-------------------------------------+
| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership |
| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests |
| ``<=``, ``>``, ``>=``, ``!=``, ``==`` | |
| ``*``, ``@``, ``/``, ``//``, ``%`` | Multiplication, matrix |
| | multiplication, division, floor |
| | division, remainder [#]_ |
+-----------------------------------------------+-------------------------------------+
| ``|`` | Bitwise OR |
| ``+``, ``-`` | Addition and subtraction |
+-----------------------------------------------+-------------------------------------+
| ``^`` | Bitwise XOR |
| ``<<``, ``>>`` | Shifts |
+-----------------------------------------------+-------------------------------------+
| ``&`` | Bitwise AND |
+-----------------------------------------------+-------------------------------------+
| ``<<``, ``>>`` | Shifts |
| ``^`` | Bitwise XOR |
+-----------------------------------------------+-------------------------------------+
| ``+``, ``-`` | Addition and subtraction |
| ``|`` | Bitwise OR |
+-----------------------------------------------+-------------------------------------+
| ``*``, ``@``, ``/``, ``//``, ``%`` | Multiplication, matrix |
| | multiplication, division, floor |
| | division, remainder [#]_ |
| :keyword:`in`, :keyword:`not in`, | Comparisons, including membership |
| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests |
| ``<=``, ``>``, ``>=``, ``!=``, ``==`` | |
+-----------------------------------------------+-------------------------------------+
| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |
| :keyword:`not` ``x`` | Boolean NOT |
+-----------------------------------------------+-------------------------------------+
| ``**`` | Exponentiation [#]_ |
| :keyword:`and` | Boolean AND |
+-----------------------------------------------+-------------------------------------+
| :keyword:`await` ``x`` | Await expression |
| :keyword:`or` | Boolean OR |
+-----------------------------------------------+-------------------------------------+
| ``x[index]``, ``x[index:index]``, | Subscription, slicing, |
| ``x(arguments...)``, ``x.attribute`` | call, attribute reference |
| :keyword:`if <if_expr>` -- :keyword:`!else` | Conditional expression |
+-----------------------------------------------+-------------------------------------+
| ``(expressions...)``, | Binding or parenthesized |
| | expression, |
| ``[expressions...]``, | list display, |
| ``{key: value...}``, | dictionary display, |
| ``{expressions...}`` | set display |
| :keyword:`lambda` | Lambda expression |
+-----------------------------------------------+-------------------------------------+
| ``:=`` | Assignment expression |
+-----------------------------------------------+-------------------------------------+


Expand Down Expand Up @@ -1884,8 +1884,8 @@ precedence and have a left-to-right chaining feature as described in the
the :keyword:`is` operator, like those involving comparisons between instance
methods, or constants. Check their documentation for more info.

.. [#] The ``%`` operator is also used for string formatting; the same
precedence applies.

.. [#] The power operator ``**`` binds less tightly than an arithmetic or
bitwise unary operator on its right, that is, ``2**-1`` is ``0.5``.

.. [#] The ``%`` operator is also used for string formatting; the same
precedence applies.