♦ Python If Elif Else
♣ About Python If Elif Else
if, elif, and else are conditional statements.Deterministic decisions can be made through these literals.
Compares two same/different Data Types over operators, such as:-
- Greater Than: a > b
- Greater Than or Equal to: a >= b
- Less Than: a < b
- Less Than or Equal to: a <= b
- Equal to: a == b
- Not Equal to: a != b
♣ Example1: If in Python
if condition code block is executed when the associated if the given condition is satisfied(true). Example
Input:
Output:
♣ Example2: ElIf in Python
elif keyword is python's way of saying "if the previous conditions were not true, then try current given condition" and execute the respective code block. Example
Input:
Output:
♣ Example3: Else in Python
else condition block is executed when all prior conditions(if condition, elif condition(s)) are false. Example
Input:
Output: