diff options
Diffstat (limited to 'Doc/reference/expressions.rst')
-rw-r--r-- | Doc/reference/expressions.rst | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst index 604a8f0..b1717cf 100644 --- a/Doc/reference/expressions.rst +++ b/Doc/reference/expressions.rst @@ -785,14 +785,14 @@ number. (In earlier versions it raised 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` @@ -1240,56 +1240,46 @@ comparisons, including tests, which all have the same precedence and chain from left to right --- see section :ref:`comparisons` --- and exponentiation, which groups from right to left). -+----------------------------------------------+-------------------------------------+ -| Operator | Description | -+==============================================+=====================================+ -| :keyword:`lambda` | Lambda expression | -+----------------------------------------------+-------------------------------------+ -| :keyword:`or` | Boolean OR | -+----------------------------------------------+-------------------------------------+ -| :keyword:`and` | Boolean AND | -+----------------------------------------------+-------------------------------------+ -| :keyword:`not` *x* | Boolean NOT | -+----------------------------------------------+-------------------------------------+ -| :keyword:`in`, :keyword:`not` :keyword:`in` | Membership tests | -+----------------------------------------------+-------------------------------------+ -| :keyword:`is`, :keyword:`is not` | Identity tests | -+----------------------------------------------+-------------------------------------+ -| ``<``, ``<=``, ``>``, ``>=``, ``!=``, ``==`` | Comparisons | -+----------------------------------------------+-------------------------------------+ -| ``|`` | Bitwise OR | -+----------------------------------------------+-------------------------------------+ -| ``^`` | Bitwise XOR | -+----------------------------------------------+-------------------------------------+ -| ``&`` | Bitwise AND | -+----------------------------------------------+-------------------------------------+ -| ``<<``, ``>>`` | Shifts | -+----------------------------------------------+-------------------------------------+ -| ``+``, ``-`` | Addition and subtraction | -+----------------------------------------------+-------------------------------------+ -| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder | -+----------------------------------------------+-------------------------------------+ -| ``+x``, ``-x`` | Positive, negative | -+----------------------------------------------+-------------------------------------+ -| ``~x`` | Bitwise not | -+----------------------------------------------+-------------------------------------+ -| ``**`` | Exponentiation | -+----------------------------------------------+-------------------------------------+ -| ``x[index]`` | Subscription | -+----------------------------------------------+-------------------------------------+ -| ``x[index:index]`` | Slicing | -+----------------------------------------------+-------------------------------------+ -| ``x(arguments...)`` | Call | -+----------------------------------------------+-------------------------------------+ -| ``x.attribute`` | Attribute reference | -+----------------------------------------------+-------------------------------------+ -| ``(expressions...)`` | Binding, tuple display, generator | -| | expressions | -+----------------------------------------------+-------------------------------------+ -| ``[expressions...]`` | List display | -+----------------------------------------------+-------------------------------------+ -| ``{expressions...}`` | Dictionary or set display | -+----------------------------------------------+-------------------------------------+ + ++-----------------------------------------------+-------------------------------------+ +| Operator | Description | ++===============================================+=====================================+ +| :keyword:`lambda` | Lambda expression | ++-----------------------------------------------+-------------------------------------+ +| :keyword:`or` | Boolean OR | ++-----------------------------------------------+-------------------------------------+ +| :keyword:`and` | Boolean AND | ++-----------------------------------------------+-------------------------------------+ +| :keyword:`not` *x* | Boolean NOT | ++-----------------------------------------------+-------------------------------------+ +| :keyword:`in`, :keyword:`not` :keyword:`in`, | Comparisons, including membership | +| :keyword:`is`, :keyword:`is not`, ``<``, | tests and identity tests, | +| ``<=``, ``>``, ``>=``, ``<>``, ``!=``, ``==`` | | ++-----------------------------------------------+-------------------------------------+ +| ``|`` | Bitwise OR | ++-----------------------------------------------+-------------------------------------+ +| ``^`` | Bitwise XOR | ++-----------------------------------------------+-------------------------------------+ +| ``&`` | Bitwise AND | ++-----------------------------------------------+-------------------------------------+ +| ``<<``, ``>>`` | Shifts | ++-----------------------------------------------+-------------------------------------+ +| ``+``, ``-`` | Addition and subtraction | ++-----------------------------------------------+-------------------------------------+ +| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder | ++-----------------------------------------------+-------------------------------------+ +| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT | ++-----------------------------------------------+-------------------------------------+ +| ``**`` | Exponentiation [#]_ | ++-----------------------------------------------+-------------------------------------+ +| ``x[index]``, ``x[index:index]``, | Subscription, slicing, | +| ``x(arguments...)``, ``x.attribute`` | call, attribute reference | ++-----------------------------------------------+-------------------------------------+ +| ``(expressions...)``, | Binding or tuple display, | +| ``[expressions...]``, | list display, | +| ``{key:datum...}``, | dictionary display, | ++-----------------------------------------------+-------------------------------------+ + .. rubric:: Footnotes @@ -1327,3 +1317,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``. |