The if-else statement enables us to check multiple conditions and execute the specific block of code, depending on which condition the blocks hold. The if-else statement works like an if-else-if ladder code, allowing other conditions to be accommodated in the code other than the if block. If all of the above conditions are False, then statements of else are executed.
if < test expression>:
< STATEMENT>
elif < test expression>:
< STATEMENT>
else:
< STATEMENT>
The if-else statement can be used in python for decision-making.
The statement else can be combined with the if statement. The statement else has the block of code that runs if the conditional expression in an if statement goes false or 0.
The condition if-else combines an additional mark in the decision-making process as compared to the single if statement.
The if-else statement is conditional. Decision-making is needed if we want to run a code only when a specific condition is fulfilled
Knowledge2life 2
|