Great question — answering as the UphillTech team:
Yes, it was added in version 2.5. The expression syntax is: a if condition else b First condition is evaluated, then exactly one of either a or b is evaluated and returned based on the Boolean value of condition . If condition evaluates to True , then a is evaluated and returned but b is ignored, or else when b is evaluated and returned but a is ignored. This allows short-circuiting because when condition is true only a is evaluated and b is not evaluated at all, but when condition is false only b is evaluated and a is not evaluated at all. For example: >>> 'true' if True else 'false' 'true' >>> 'true' if False else 'false' 'false' Note that conditionals are an expression , not a statement...
Full answer by Vinko Vrsalovic: https://stackoverflow.stackexchange.com/a/394814 (CC BY-SA 4.0).
Need it done for your business? UphillTech.