How to Short Hand If Else Statement in Python


In this example, we will learn how to short hand if else statement with multiple else in Python.

Source Code

x = 8
y = 20
print('x is greater than y') if x > y else print('x and y are equal') if x == y else print('x is less than y')

Output:

x is less than y
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement