समापन की आवश्यकताएँ
3. if-else if - else Statement
When there are multiple conditions to check, you can use the elif clause (short for "else if"). Python evaluates each condition one by one until it finds one that is True. If none are True, the else block is executed.
Syntax:
if expression1 :
statement_1
statement_2
....
elif expression2 :
statement_3
statement_4
....
elif expression3 :
statement_5
statement_6
....................
else :
statement_7
statement_8
In the above case Python evaluates each expression (i.e. the condition) one by one and if a true condition is found the statement(s) block under that expression will be executed. If no true condition is found the statement(s) block under else will be executed. In the following example, we have applied if, series of elif and else to get the type of a variable.
Output:
Type of the variable is Complex
"Python if elif else" by w3resource is licensed under CC BY-SA 4.0