-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathif_else_inline.py
More file actions
14 lines (12 loc) · 791 Bytes
/
Copy pathif_else_inline.py
File metadata and controls
14 lines (12 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""The syntax of a inline "if-else"-statements in Python."""
# If conditionForUsingValueA evaluates to True, then valueA will be
# assigned to variable. Otherwise, valueB will be assigned to variable.
variable = valueA if conditionForUsingValueA else valueB
# If conditionForUsingValueA evaluates to True, then valueA will be
# assigned to variable. Otherwise, conditionForUsingValueB is evaluated.
# If conditionForUsingValueB did evaluate to True, then valueB is
# assigned to variable (but of course, only if conditionForUsingValueA
# was False). If conditionForUsingValueB did evaluate to False (and
# conditionForUsingValueA was also False), then valueC will be assigned
# to variable.
variable = valueA if conditionForUsingValueA else (valueB if conditionForUsingValueB else valueC)