summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/executionmodel.rst4
-rw-r--r--Doc/reference/expressions.rst35
2 files changed, 28 insertions, 11 deletions
diff --git a/Doc/reference/executionmodel.rst b/Doc/reference/executionmodel.rst
index 90791d2..b4c29b1 100644
--- a/Doc/reference/executionmodel.rst
+++ b/Doc/reference/executionmodel.rst
@@ -120,7 +120,7 @@ namespace is searched. The global statement must precede all uses of the name.
.. index:: pair: restricted; execution
-The built-in namespace associated with the execution of a code block is actually
+The builtins namespace associated with the execution of a code block is actually
found by looking up the name ``__builtins__`` in its global namespace; this
should be a dictionary or a module (in the latter case the module's dictionary
is used). By default, when in the :mod:`__main__` module, ``__builtins__`` is
@@ -132,7 +132,7 @@ weak form of restricted execution.
.. impl-detail::
Users should not touch ``__builtins__``; it is strictly an implementation
- detail. Users wanting to override values in the built-in namespace should
+ detail. Users wanting to override values in the builtins namespace should
:keyword:`import` the :mod:`builtins` module and modify its
attributes appropriately.
diff --git a/Doc/reference/expressions.rst b/Doc/reference/expressions.rst
index d074ebb..d0acd20 100644
--- a/Doc/reference/expressions.rst
+++ b/Doc/reference/expressions.rst
@@ -1113,12 +1113,7 @@ Boolean operations
pair: Conditional; expression
pair: Boolean; operation
-Boolean operations have the lowest priority of all Python operations:
-
.. productionlist::
- expression: `conditional_expression` | `lambda_form`
- expression_nocond: `or_test` | `lambda_form_nocond`
- conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
or_test: `and_test` | `or_test` "or" `and_test`
and_test: `not_test` | `and_test` "and" `not_test`
not_test: `comparison` | "not" `not_test`
@@ -1135,10 +1130,6 @@ truth value by providing a :meth:`__bool__` method.
The operator :keyword:`not` yields ``True`` if its argument is false, ``False``
otherwise.
-The expression ``x if C else y`` first evaluates *C* (*not* *x*); if *C* is
-true, *x* is evaluated and its value is returned; otherwise, *y* is evaluated
-and its value is returned.
-
.. index:: operator: and
The expression ``x and y`` first evaluates *x*; if *x* is false, its value is
@@ -1158,6 +1149,30 @@ not bother to return a value of the same type as its argument, so e.g., ``not
'foo'`` yields ``False``, not ``''``.)
+Conditional Expressions
+=======================
+
+.. versionadded:: 2.5
+
+.. index::
+ pair: conditional; expression
+ pair: ternary; operator
+
+.. productionlist::
+ conditional_expression: `or_test` ["if" `or_test` "else" `expression`]
+ expression: `conditional_expression` | `lambda_form`
+ expression_nocond: `or_test` | `lambda_form_nocond`
+
+Conditional expressions (sometimes called a "ternary operator") have the lowest
+priority of all Python operations.
+
+The expression ``x if C else y`` first evaluates the condition, *C* (*not* *x*);
+if *C* is true, *x* is evaluated and its value is returned; otherwise, *y* is
+evaluated and its value is returned.
+
+See :pep:`308` for more details about conditional expressions.
+
+
.. _lambdas:
.. _lambda:
@@ -1252,6 +1267,8 @@ groups from right to left).
+===============================================+=====================================+
| :keyword:`lambda` | Lambda expression |
+-----------------------------------------------+-------------------------------------+
+| :keyword:`if` -- :keyword:`else` | Conditional expression |
++-----------------------------------------------+-------------------------------------+
| :keyword:`or` | Boolean OR |
+-----------------------------------------------+-------------------------------------+
| :keyword:`and` | Boolean AND |