Conditional expressions use the functionality of an if-else statement in a different way.
The expression returns an output based on the condition we provide. This output can be stored in a variable.
A conditional expression can be written in the following way:
output_value1 if condition else output_value2
If the if condition is fulfilled, the output would be output_value1. Otherwise, it would be output_value2.
Let’s refactor the previous if-else statement into a conditional expression: