<div dir="ltr">`if-unless` expressions in Python<br><br>    if condition1 expr unless condition2<br><br>is an expression that roughly reduces to<br><br>    expr if condition1 and not condition2 else EMPTY<br><br><br>This definition means that expr is only evaluated if `condition1 and not condition2` evaluates to true. It also means `not condition2` is only evaluated if `condition1` is true.<br><br># EMPTY<br><br>EMPTY is not actually a real Python value-- it's a value that collapses into nothing when used inside a statement expression:<br><br>    print([<br>      if False never_called() unless False,<br>      if False never_called() unless False,<br>    ]) # => []<br><br>    print([<br>      3,<br>      if False never_called() unless False,<br>      if False never_called() unless False,<br>      2,<br>      if True 5 unless False,<br>      4<br>    ]) # => [3, 2, 5, 4]<br><br><br>EMPTY is neither a constant exposed to the Python runtime nor a symbol. It's a compiler-internal value.<br><br># Use cases<br><br>Assertions.<br><br>    assert if condition1 predicate(object) unless condition2<br><br>(This would be more readable with assert expressions.)<br><br>Macros.<br><br># Equivalent syntax in existing Python<br><br>As a statement:<br><br>if condition1 and not condition2: predicate(object)<br><br>predicate(object) if condition1 and not condition2<br><br># Backward compatibility<br><br>The `unless` word is only recognized as special inside `if-unless` statements. The continued use of the word as a variable name is discouraged.</div>