Using "else" in a comprehension
Briefly

But what if you don't want to filter down results, but instead you'd like to have one expression evaluated or another? Do list comprehensions support else? This list comprehension isn't valid: Python's list comprehensions don't have any support for an else keyword. But else does work in comprehensions...
Python's version of a ternary operator: This expression checks a condition and evaluates one expression if the condition is truthy, or another expression if the condition is falsey. These are sometimes called inline if expressions or conditional expressions.
Read at Pythonmorsels
[
]
[
|
]