mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
Merged revisions 78760,78771-78773,78802,78922,78952 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78760 | georg.brandl | 2010-03-07 16:23:59 +0100 (So, 07 Mär 2010) | 1 line #5341: more built-in vs builtin fixes. ........ r78771 | georg.brandl | 2010-03-07 21:58:31 +0100 (So, 07 Mär 2010) | 1 line #8085: The function is called PyObject_NewVar, not PyObject_VarNew. ........ r78772 | georg.brandl | 2010-03-07 22:12:28 +0100 (So, 07 Mär 2010) | 1 line #8039: document conditional expressions better, giving them their own section. ........ r78773 | georg.brandl | 2010-03-07 22:32:06 +0100 (So, 07 Mär 2010) | 1 line #8044: document Py_{Enter,Leave}RecursiveCall functions. ........ r78802 | georg.brandl | 2010-03-08 17:28:40 +0100 (Mo, 08 Mär 2010) | 1 line Fix typo. ........ r78922 | georg.brandl | 2010-03-13 14:41:58 +0100 (Sa, 13 Mär 2010) | 1 line Update for new download location. ........ r78952 | georg.brandl | 2010-03-14 10:55:08 +0100 (So, 14 Mär 2010) | 1 line #8137: add iso-8859-16 to the standard encodings table. ........
This commit is contained in:
parent
c0e22b7889
commit
93dc9eb2a3
10 changed files with 114 additions and 65 deletions
|
|
@ -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 |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue