Conditional expressions¶
The expression x if C else y
first evaluates the condition, C
rather than x
. If C
is true, x
is evaluated and its value is returned; otherwise, y
is evaluated and its value is returned.
>>> C = True
>>> a = 1 if C else 0
>>> a
1