From 4639dfd3d13aa309d909c633b65c25ecc5130cb0 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Mon, 1 Apr 2024 17:24:21 +0300 Subject: [PATCH 1/7] docs: Clarify associativity of operators. --- tutorials/scripting/gdscript/gdscript_basics.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 65588bf0a1f..31e1083eaf9 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -330,8 +330,8 @@ The following is the list of supported operators and their precedence. 3. For negative values, the ``%`` operator and ``fmod()`` use `truncation `_ instead of rounding towards negative infinity. This means that the remainder has a sign. If you need the remainder in a mathematical sense, use the :ref:`posmod() ` and :ref:`fposmod() ` functions instead. - 4. The ``**`` operator is `left-associative `_. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. - Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. + 4. All operators are `left-associative `_ including the ``**`` operator. This means that ``2 ** 2 ** 3`` is + equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. 5. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause a runtime error. If you're not sure about the types of the operands, you can safely use the :ref:`is_same() ` function (but note that it is more strict about types and references). To compare floats, use the :ref:`is_equal_approx() ` From dfe197b4c1a1229e2ed47a630891b2dc16c77897 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Mon, 1 Apr 2024 17:27:01 +0300 Subject: [PATCH 2/7] misc: Add missing (?) comma. --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 31e1083eaf9..9b417ee9271 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -330,7 +330,7 @@ The following is the list of supported operators and their precedence. 3. For negative values, the ``%`` operator and ``fmod()`` use `truncation `_ instead of rounding towards negative infinity. This means that the remainder has a sign. If you need the remainder in a mathematical sense, use the :ref:`posmod() ` and :ref:`fposmod() ` functions instead. - 4. All operators are `left-associative `_ including the ``**`` operator. This means that ``2 ** 2 ** 3`` is + 4. All operators are `left-associative `_, including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. 5. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause a runtime error. If you're not sure about the types of the operands, you can safely use the :ref:`is_same() ` function From 4da643f15d4b8de0eafacf33641e907857669eb4 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Mon, 1 Apr 2024 17:38:50 +0300 Subject: [PATCH 3/7] docs: Move associativity note to the top of the section. --- tutorials/scripting/gdscript/gdscript_basics.rst | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 9b417ee9271..e4a7b3f2605 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -224,7 +224,9 @@ in case you want to take a look under the hood. Operators ~~~~~~~~~ -The following is the list of supported operators and their precedence. +The following is the list of supported operators and their precedence. All operators are `left-associative `_, +including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for +example ``2 ** (2 ** 3)``. +---------------------------------------+-----------------------------------------------------------------------------+ | **Operator** | **Description** | @@ -251,10 +253,6 @@ The following is the list of supported operators and their precedence. | | | | | Multiplies ``x`` by itself ``y`` times, similar to calling | | | :ref:`pow() ` function. | -| | | -| | **Note:** In GDScript, the ``**`` operator is | -| | `left-associative `_. | -| | See a detailed note after the table. | +---------------------------------------+-----------------------------------------------------------------------------+ | ``~x`` | Bitwise NOT | +---------------------------------------+-----------------------------------------------------------------------------+ @@ -330,9 +328,7 @@ The following is the list of supported operators and their precedence. 3. For negative values, the ``%`` operator and ``fmod()`` use `truncation `_ instead of rounding towards negative infinity. This means that the remainder has a sign. If you need the remainder in a mathematical sense, use the :ref:`posmod() ` and :ref:`fposmod() ` functions instead. - 4. All operators are `left-associative `_, including the ``**`` operator. This means that ``2 ** 2 ** 3`` is - equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. - 5. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause + 4. The ``==`` and ``!=`` operators sometimes allow you to compare values of different types (for example, ``1 == 1.0`` is true), but in other cases it can cause a runtime error. If you're not sure about the types of the operands, you can safely use the :ref:`is_same() ` function (but note that it is more strict about types and references). To compare floats, use the :ref:`is_equal_approx() ` and :ref:`is_zero_approx() ` functions instead. From 82a8fe2892c62c8f3631207a34e202666d341388 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 4 Apr 2024 13:07:36 +0300 Subject: [PATCH 4/7] Add associativity table column. --- .../scripting/gdscript/gdscript_basics.rst | 184 +++++++++--------- 1 file changed, 91 insertions(+), 93 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index e4a7b3f2605..fd277653b6f 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -224,99 +224,97 @@ in case you want to take a look under the hood. Operators ~~~~~~~~~ -The following is the list of supported operators and their precedence. All operators are `left-associative `_, -including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for -example ``2 ** (2 ** 3)``. - -+---------------------------------------+-----------------------------------------------------------------------------+ -| **Operator** | **Description** | -+=======================================+=============================================================================+ -| ``(`` ``)`` | Grouping (highest priority) | -| | | -| | Parentheses are not really an operator, but allow you to explicitly specify | -| | the precedence of an operation. | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x[index]`` | Subscription | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x.attribute`` | Attribute reference | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``foo()`` | Function call | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``await x`` | `Awaiting for signals or coroutines`_ | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x is Node`` | Type checking | -| | ``x is not Node`` | | -| | See also :ref:`is_instance_of() ` | -| | function. | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x ** y`` | Power | -| | | -| | Multiplies ``x`` by itself ``y`` times, similar to calling | -| | :ref:`pow() ` function. | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``~x`` | Bitwise NOT | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``+x`` | Identity / Negation | -| | ``-x`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x * y`` | Multiplication / Division / Remainder | -| | ``x / y`` | | -| | ``x % y`` | The ``%`` operator is additionally used for | -| | :ref:`format strings `. | -| | | -| | **Note:** These operators have the same behavior as C++, which may be | -| | unexpected for users coming from Python, JavaScript, etc. See a detailed | -| | note after the table. | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x + y`` | Addition (or Concatenation) / Subtraction | -| | ``x - y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x << y`` | Bit shifting | -| | ``x >> y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x & y`` | Bitwise AND | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x ^ y`` | Bitwise XOR | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x | y`` | Bitwise OR | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x == y`` | Comparison | -| | ``x != y`` | | -| | ``x < y`` | See a detailed note after the table. | -| | ``x > y`` | | -| | ``x <= y`` | | -| | ``x >= y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x in y`` | Inclusion checking | -| | ``x not in y`` | | -| | ``in`` is also used with the for_ keyword as part of the syntax. | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``not x`` | Boolean NOT and its :ref:`unrecommended ` alias | -| | ``!x`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x and y`` | Boolean AND and its :ref:`unrecommended ` alias | -| | ``x && y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x or y`` | Boolean OR and its :ref:`unrecommended ` alias | -| | ``x || y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``true_expr if cond else false_expr`` | Ternary if/else | -+---------------------------------------+-----------------------------------------------------------------------------+ -| ``x as Node`` | `Type casting `_ | -+---------------------------------------+-----------------------------------------------------------------------------+ -| | ``x = y`` | Assignment (lowest priority) | -| | ``x += y`` | | -| | ``x -= y`` | You cannot use an assignment operator inside an expression. | -| | ``x *= y`` | | -| | ``x /= y`` | | -| | ``x **= y`` | | -| | ``x %= y`` | | -| | ``x &= y`` | | -| | ``x |= y`` | | -| | ``x ^= y`` | | -| | ``x <<= y`` | | -| | ``x >>= y`` | | -+---------------------------------------+-----------------------------------------------------------------------------+ +The following is the list of supported operators, their precedence, and `associativity `_. + ++---------------------------------------+-----------------------------------------------------------------------------+-------------------+ +| **Operator** | **Description** | **Associativity** | ++=======================================+=============================================================================+===================+ +| ``(`` ``)`` | Grouping (highest priority) | N/A | +| | | | +| | Parentheses are not really an operator, but allow you to explicitly specify | | +| | the precedence of an operation. | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x[index]`` | Subscription | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x.attribute`` | Attribute reference | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``foo()`` | Function call | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``await x`` | `Awaiting for signals or coroutines`_ | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x is Node`` | Type checking | Left | +| | ``x is not Node`` | | | +| | See also :ref:`is_instance_of() ` | | +| | function. | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x ** y`` | Power | Left | +| | | | +| | Multiplies ``x`` by itself ``y`` times, similar to calling | | +| | :ref:`pow() ` function. | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``~x`` | Bitwise NOT | Right | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``+x`` | Identity / Negation | Right | +| | ``-x`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x * y`` | Multiplication / Division / Remainder | Left | +| | ``x / y`` | | | +| | ``x % y`` | The ``%`` operator is additionally used for | | +| | :ref:`format strings `. | | +| | | | +| | **Note:** These operators have the same behavior as C++, which may be | | +| | unexpected for users coming from Python, JavaScript, etc. See a detailed | | +| | note after the table. | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x + y`` | Addition (or Concatenation) / Subtraction | Left | +| | ``x - y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x << y`` | Bit shifting | Left | +| | ``x >> y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x & y`` | Bitwise AND | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x ^ y`` | Bitwise XOR | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x | y`` | Bitwise OR | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x == y`` | Comparison | Left | +| | ``x != y`` | | | +| | ``x < y`` | See a detailed note after the table. | | +| | ``x > y`` | | | +| | ``x <= y`` | | | +| | ``x >= y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x in y`` | Inclusion checking | Left | +| | ``x not in y`` | | | +| | ``in`` is also used with the for_ keyword as part of the syntax. | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``not x`` | Boolean NOT and its :ref:`unrecommended ` alias | Right | +| | ``!x`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x and y`` | Boolean AND and its :ref:`unrecommended ` alias | Left | +| | ``x && y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x or y`` | Boolean OR and its :ref:`unrecommended ` alias | Left | +| | ``x || y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``true_expr if cond else false_expr`` | Ternary if/else | Right | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| ``x as Node`` | `Type casting `_ | Left | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| +| | ``x = y`` | Assignment (lowest priority) | Left | +| | ``x += y`` | | | +| | ``x -= y`` | You cannot use an assignment operator inside an expression. | | +| | ``x *= y`` | | | +| | ``x /= y`` | | | +| | ``x **= y`` | | | +| | ``x %= y`` | | | +| | ``x &= y`` | | | +| | ``x |= y`` | | | +| | ``x ^= y`` | | | +| | ``x <<= y`` | | | +| | ``x >>= y`` | | | ++---------------------------------------+-----------------------------------------------------------------------------+-------------------| .. note:: From 8948e3f77a192ed18db622ce6bf30abd6404495c Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 4 Apr 2024 13:08:43 +0300 Subject: [PATCH 5/7] Add missed associativity for `await`. --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index fd277653b6f..ce37dabfcec 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -240,7 +240,7 @@ The following is the list of supported operators, their precedence, and `associa +---------------------------------------+-----------------------------------------------------------------------------+-------------------| | ``foo()`` | Function call | Left | +---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``await x`` | `Awaiting for signals or coroutines`_ | | +| ``await x`` | `Awaiting for signals or coroutines`_ | Right | +---------------------------------------+-----------------------------------------------------------------------------+-------------------| | | ``x is Node`` | Type checking | Left | | | ``x is not Node`` | | | From 5d1fe640362711bb16c618568bdf19ec15a59174 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 4 Apr 2024 13:15:28 +0300 Subject: [PATCH 6/7] Remove the table --- tutorials/scripting/gdscript/gdscript_basics.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index e4a7b3f2605..5d737a526cf 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -224,9 +224,9 @@ in case you want to take a look under the hood. Operators ~~~~~~~~~ -The following is the list of supported operators and their precedence. All operators are `left-associative `_, +The following is the list of supported operators and their precedence. All binary operators are `left-associative `_, including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for -example ``2 ** (2 ** 3)``. +example ``2 ** (2 ** 3)``. The ternary ``if/else`` operator is right-associative. +---------------------------------------+-----------------------------------------------------------------------------+ | **Operator** | **Description** | From 897bff376ddd2b39f12e152c158a30648ea10259 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 4 Apr 2024 13:21:50 +0300 Subject: [PATCH 7/7] Remove the table --- .../scripting/gdscript/gdscript_basics.rst | 184 +++++++++--------- 1 file changed, 90 insertions(+), 94 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index f74a35bdc48..5d737a526cf 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -224,103 +224,99 @@ in case you want to take a look under the hood. Operators ~~~~~~~~~ -<<<<<<< HEAD The following is the list of supported operators and their precedence. All binary operators are `left-associative `_, including the ``**`` operator. This means that ``2 ** 2 ** 3`` is equal to ``(2 ** 2) ** 3``. Use parentheses to explicitly specify precedence you need, for example ``2 ** (2 ** 3)``. The ternary ``if/else`` operator is right-associative. -======= -The following is the list of supported operators, their precedence, and `associativity `_. ->>>>>>> origin/docs/op-assoc - -+---------------------------------------+-----------------------------------------------------------------------------+-------------------+ -| **Operator** | **Description** | **Associativity** | -+=======================================+=============================================================================+===================+ -| ``(`` ``)`` | Grouping (highest priority) | N/A | -| | | | -| | Parentheses are not really an operator, but allow you to explicitly specify | | -| | the precedence of an operation. | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x[index]`` | Subscription | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x.attribute`` | Attribute reference | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``foo()`` | Function call | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``await x`` | `Awaiting for signals or coroutines`_ | Right | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x is Node`` | Type checking | Left | -| | ``x is not Node`` | | | -| | See also :ref:`is_instance_of() ` | | -| | function. | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x ** y`` | Power | Left | -| | | | -| | Multiplies ``x`` by itself ``y`` times, similar to calling | | -| | :ref:`pow() ` function. | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``~x`` | Bitwise NOT | Right | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``+x`` | Identity / Negation | Right | -| | ``-x`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x * y`` | Multiplication / Division / Remainder | Left | -| | ``x / y`` | | | -| | ``x % y`` | The ``%`` operator is additionally used for | | -| | :ref:`format strings `. | | -| | | | -| | **Note:** These operators have the same behavior as C++, which may be | | -| | unexpected for users coming from Python, JavaScript, etc. See a detailed | | -| | note after the table. | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x + y`` | Addition (or Concatenation) / Subtraction | Left | -| | ``x - y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x << y`` | Bit shifting | Left | -| | ``x >> y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x & y`` | Bitwise AND | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x ^ y`` | Bitwise XOR | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x | y`` | Bitwise OR | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x == y`` | Comparison | Left | -| | ``x != y`` | | | -| | ``x < y`` | See a detailed note after the table. | | -| | ``x > y`` | | | -| | ``x <= y`` | | | -| | ``x >= y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x in y`` | Inclusion checking | Left | -| | ``x not in y`` | | | -| | ``in`` is also used with the for_ keyword as part of the syntax. | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``not x`` | Boolean NOT and its :ref:`unrecommended ` alias | Right | -| | ``!x`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x and y`` | Boolean AND and its :ref:`unrecommended ` alias | Left | -| | ``x && y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x or y`` | Boolean OR and its :ref:`unrecommended ` alias | Left | -| | ``x || y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``true_expr if cond else false_expr`` | Ternary if/else | Right | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| ``x as Node`` | `Type casting `_ | Left | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| -| | ``x = y`` | Assignment (lowest priority) | Left | -| | ``x += y`` | | | -| | ``x -= y`` | You cannot use an assignment operator inside an expression. | | -| | ``x *= y`` | | | -| | ``x /= y`` | | | -| | ``x **= y`` | | | -| | ``x %= y`` | | | -| | ``x &= y`` | | | -| | ``x |= y`` | | | -| | ``x ^= y`` | | | -| | ``x <<= y`` | | | -| | ``x >>= y`` | | | -+---------------------------------------+-----------------------------------------------------------------------------+-------------------| + ++---------------------------------------+-----------------------------------------------------------------------------+ +| **Operator** | **Description** | ++=======================================+=============================================================================+ +| ``(`` ``)`` | Grouping (highest priority) | +| | | +| | Parentheses are not really an operator, but allow you to explicitly specify | +| | the precedence of an operation. | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x[index]`` | Subscription | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x.attribute`` | Attribute reference | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``foo()`` | Function call | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``await x`` | `Awaiting for signals or coroutines`_ | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x is Node`` | Type checking | +| | ``x is not Node`` | | +| | See also :ref:`is_instance_of() ` | +| | function. | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x ** y`` | Power | +| | | +| | Multiplies ``x`` by itself ``y`` times, similar to calling | +| | :ref:`pow() ` function. | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``~x`` | Bitwise NOT | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``+x`` | Identity / Negation | +| | ``-x`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x * y`` | Multiplication / Division / Remainder | +| | ``x / y`` | | +| | ``x % y`` | The ``%`` operator is additionally used for | +| | :ref:`format strings `. | +| | | +| | **Note:** These operators have the same behavior as C++, which may be | +| | unexpected for users coming from Python, JavaScript, etc. See a detailed | +| | note after the table. | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x + y`` | Addition (or Concatenation) / Subtraction | +| | ``x - y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x << y`` | Bit shifting | +| | ``x >> y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x & y`` | Bitwise AND | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x ^ y`` | Bitwise XOR | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x | y`` | Bitwise OR | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x == y`` | Comparison | +| | ``x != y`` | | +| | ``x < y`` | See a detailed note after the table. | +| | ``x > y`` | | +| | ``x <= y`` | | +| | ``x >= y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x in y`` | Inclusion checking | +| | ``x not in y`` | | +| | ``in`` is also used with the for_ keyword as part of the syntax. | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``not x`` | Boolean NOT and its :ref:`unrecommended ` alias | +| | ``!x`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x and y`` | Boolean AND and its :ref:`unrecommended ` alias | +| | ``x && y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x or y`` | Boolean OR and its :ref:`unrecommended ` alias | +| | ``x || y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``true_expr if cond else false_expr`` | Ternary if/else | ++---------------------------------------+-----------------------------------------------------------------------------+ +| ``x as Node`` | `Type casting `_ | ++---------------------------------------+-----------------------------------------------------------------------------+ +| | ``x = y`` | Assignment (lowest priority) | +| | ``x += y`` | | +| | ``x -= y`` | You cannot use an assignment operator inside an expression. | +| | ``x *= y`` | | +| | ``x /= y`` | | +| | ``x **= y`` | | +| | ``x %= y`` | | +| | ``x &= y`` | | +| | ``x |= y`` | | +| | ``x ^= y`` | | +| | ``x <<= y`` | | +| | ``x >>= y`` | | ++---------------------------------------+-----------------------------------------------------------------------------+ .. note::