summaryrefslogtreecommitdiff
path: root/Doc/reference/expressions.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/reference/expressions.rst')
-rw-r--r--Doc/reference/expressions.rst48
1 files changed, 37 insertions, 11 deletions
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index 29ef0b7766..5c33ce6f0d 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -390,6 +390,7 @@ on the right hand side of an assignment statement.
to sub-generators easy.
.. index:: object: generator
+.. _generator-methods:
Generator-iterator methods
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -443,12 +444,12 @@ is already executing raises a :exc:`ValueError` exception.
.. method:: generator.close()
Raises a :exc:`GeneratorExit` at the point where the generator function was
- paused. If the generator function then raises :exc:`StopIteration` (by
- exiting normally, or due to already being closed) or :exc:`GeneratorExit` (by
- not catching the exception), close returns to its caller. If the generator
- yields a value, a :exc:`RuntimeError` is raised. If the generator raises any
- other exception, it is propagated to the caller. :meth:`close` does nothing
- if the generator has already exited due to an exception or normal exit.
+ paused. If the generator function then exits gracefully, is already closed,
+ or raises :exc:`GeneratorExit` (by not catching the exception), close
+ returns to its caller. If the generator yields a value, a
+ :exc:`RuntimeError` is raised. If the generator raises any other exception,
+ it is propagated to the caller. :meth:`close` does nothing if the generator
+ has already exited due to an exception or normal exit.
.. index:: single: yield; examples
@@ -811,6 +812,20 @@ a class instance:
if that method was called.
+.. _await:
+
+Await expression
+================
+
+Suspend the execution of :term:`coroutine` on an :term:`awaitable` object.
+Can only be used inside a :term:`coroutine function`.
+
+.. productionlist::
+ await: ["await"] `primary`
+
+.. versionadded:: 3.5
+
+
.. _power:
The power operator
@@ -820,7 +835,7 @@ The power operator binds more tightly than unary operators on its left; it binds
less tightly than unary operators on its right. The syntax is:
.. productionlist::
- power: `primary` ["**" `u_expr`]
+ power: `await` ["**" `u_expr`]
Thus, in an unparenthesized sequence of power and unary operators, the operators
are evaluated from right to left (this does not constrain the evaluation order
@@ -891,8 +906,9 @@ from the power operator, there are only two levels, one for multiplicative
operators and one for additive operators:
.. productionlist::
- m_expr: `u_expr` | `m_expr` "*" `u_expr` | `m_expr` "//" `u_expr` | `m_expr` "/" `u_expr`
- : | `m_expr` "%" `u_expr`
+ m_expr: `u_expr` | `m_expr` "*" `u_expr` | `m_expr` "@" `m_expr` |
+ : `m_expr` "//" `u_expr`| `m_expr` "/" `u_expr` |
+ : `m_expr` "%" `u_expr`
a_expr: `m_expr` | `a_expr` "+" `m_expr` | `a_expr` "-" `m_expr`
.. index:: single: multiplication
@@ -903,6 +919,13 @@ the other must be a sequence. In the former case, the numbers are converted to a
common type and then multiplied together. In the latter case, sequence
repetition is performed; a negative repetition factor yields an empty sequence.
+.. index:: single: matrix multiplication
+
+The ``@`` (at) operator is intended to be used for matrix multiplication. No
+builtin Python types implement this operator.
+
+.. versionadded:: 3.5
+
.. index::
exception: ZeroDivisionError
single: division
@@ -1466,13 +1489,16 @@ precedence and have a left-to-right chaining feature as described in the
+-----------------------------------------------+-------------------------------------+
| ``+``, ``-`` | Addition and subtraction |
+-----------------------------------------------+-------------------------------------+
-| ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder |
-| | [#]_ |
+| ``*``, ``@``, ``/``, ``//``, ``%`` | Multiplication, matrix |
+| | multiplication division, |
+| | remainder [#]_ |
+-----------------------------------------------+-------------------------------------+
| ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT |
+-----------------------------------------------+-------------------------------------+
| ``**`` | Exponentiation [#]_ |
+-----------------------------------------------+-------------------------------------+
+| ``await`` ``x`` | Await expression |
++-----------------------------------------------+-------------------------------------+
| ``x[index]``, ``x[index:index]``, | Subscription, slicing, |
| ``x(arguments...)``, ``x.attribute`` | call, attribute reference |
+-----------------------------------------------+-------------------------------------+