Skip to content

Commit b384220

Browse files
committed
gh-65058: Clarify the conditional expression grouping example
1 parent c6f180c commit b384220

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎Doc/reference/expressions.rst‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,10 +2426,11 @@ evaluated and its value is returned.
24262426
Conditional expressions group from right to left, so
24272427
``a if b else c if d else e`` means ``a if b else (c if d else e)``::
24282428

2429-
>>> 'spam' if True else 'eggs' if False else 'ham'
2430-
'spam'
2431-
>>> ('spam' if True else 'eggs') if False else 'ham'
2432-
'ham'
2429+
>>> n = 2
2430+
>>> print('positive' if n > 0
2431+
... else 'negative' if n < 0
2432+
... else 'zero')
2433+
positive
24332434

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

0 commit comments

Comments
 (0)