Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
38c72030
Kaydet (Commit)
38c72030
authored
Mar 07, 2010
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#8039: document conditional expressions better, giving them their own section.
üst
303e6759
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
11 deletions
+26
-11
expressions.rst
Doc/reference/expressions.rst
+26
-11
No files found.
Doc/reference/expressions.rst
Dosyayı görüntüle @
38c72030
...
...
@@ -185,6 +185,7 @@ brackets:
list_comprehension: `expression` `list_for`
list_for: "for" `target_list` "in" `old_expression_list` [`list_iter`]
old_expression_list: `old_expression` [("," `old_expression`)+ [","]]
old_expression: `or_test` | `old_lambda_form`
list_iter: `list_for` | `list_if`
list_if: "if" `old_expression` [`list_iter`]
...
...
@@ -1186,12 +1187,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`
old_expression: `or_test` | `old_lambda_form`
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`
...
...
@@ -1208,12 +1204,6 @@ special method for a way to change this.)
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.
.. versionadded:: 2.5
.. index:: operator: and
The expression ``x and y`` first evaluates *x*; if *x* is false, its value is
...
...
@@ -1233,6 +1223,29 @@ 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`
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* *a*);
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:
...
...
@@ -1326,6 +1339,8 @@ groups from right to left).
+===============================================+=====================================+
| :keyword:`lambda` | Lambda expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`if` -- :keyword:`else` | Conditional expression |
+-----------------------------------------------+-------------------------------------+
| :keyword:`or` | Boolean OR |
+-----------------------------------------------+-------------------------------------+
| :keyword:`and` | Boolean AND |
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment