Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Doc/reference/expressions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,15 @@ The expression ``x if C else y`` first evaluates the condition, *C* rather than
If *C* is true, *x* is evaluated and its value is returned; otherwise, *y* is
evaluated and its value is returned.

Conditional expressions group from right to left, so
``a if b else c if d else e`` means ``a if b else (c if d else e)``::

>>> n = 2
>>> print('positive' if n > 0
... else 'negative' if n < 0
... else 'zero')
positive

See :pep:`308` for more details about conditional expressions.


Expand Down
Loading