In this example we will show how to short hand if else statement in Python.
Source Code
x = 20
y = 8
print('x is greater than y') if x > y else print('x is not greater than y')
Output:
x is greater than y
In this example we will show how to short hand if else statement in Python.
x = 20
y = 8
print('x is greater than y') if x > y else print('x is not greater than y')
Output:
x is greater than y
In this example we will show how to short hand if else statement with multiple else in Python.
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