Python if-elif-else Ladder Condition Example


  • If-elif-else ladder

It checks first for if condition, if the condition is true, it will execute if block, otherwise it will go to next condition i.e elif.

If the condition went false, it will again move toward next elif condition, still the condition becomes true.

At last, if no condition is satisfied, finally it will execute else block.

Program
a = 9 b = 7 if b > a: print("b is greater than a") elif a == b: print("a is equal to b") else: print("a is greater than b")
Input
Output