2.4.1.3 Short Hand if-else Statement
Python Programming
Python also allows a short-hand if-else statement that can be written in a single line.
python
# Syntax of short hand if-else statement
action_if_true if condition else action_if_falsepython
temperature = 15
print("It’s a hot day") if temperature > 30 else print("It’s not a hot day")Explanation: This is the same as the previous example but written in a more compact form. The output of the code depends on the value stored in the variable “temperature”, it prints “It's a hot day" if the value is greater than 30, otherwise it prints “It's not a hot day”.