if-elif-else statements:-
if_elif_else statement मे अगर if block का condition true होगा तो if block का स्टेटमेंट प्रिंट होगा अगर। if ब्लॉक का कंडीशन false होगा तो फिर elif ब्लॉक check होगा elif true होने पे elif block का statement प्रिंट होगा। अगर if और elif दोनों false होंगे तो else block का statement प्रिंट होगा।
Syntax:-
if condition :
statement (s)
elif condition :
statement (s)
else :
statement (s)
example:-
a = 2 b = 2 if(a < b) : print(“a is less than b”) elif(a > b) : print(“a is greater than b”) else : print(“a is equal to b”) Output a is equal to b |
if-elif-else statements:-
In the if_elif_else statement, if the condition of the if block is true then the statement of the if block will be printed. If the condition of the block is false then elif block will be checked and if elif is true then the statement of elif block will be printed. If both if and elif are false then the statement of else block will be printed.
Syntax:-
if condition :
statement (s)
elif condition :
statement (s)
else :
statement (s)
example:-
a = 2 b = 2 if(a < b) : print(“a is less than b”) elif(a > b) : print(“a is greater than b”) else : print(“a is equal to b”) Output a is equal to b |