What is the difference between if else and if elif else statements?
Answers
Explanation:
The first form if-if-if tests all conditions, whereas the second if-elif-else tests only as many as needed: if it finds one condition that is True , it stops and doesn't evaluate the rest. In other words: if-elif-else is used when the conditions are mutually exclusive.
Answer: - Only one statement you can evaluate by using if else statement.
If you need to evaluate more than one statement then, if elif is used. There is no limit on the number of the if elif statement which should be used in a statement.
Detailed answer: -
If else statement: -
- The if else statement is used to execute a statement if a specified condition given is true. If the condition is false, then another statement in the optional else clause will be executed.
The syntax used to write is: -
if (condition)
statement1
// With an else clause
if (condition)
statement1
else
statement2
If elif statement: -
- The elif statement allows you to check the multiple expressions for the TRUE statement and then it executes a block of code as soon as one of the conditions evaluates to be TRUE.
The syntax used to write is: -
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
To know more about the topic, go to the below links: -
https://brainly.in/question/30204100
https://brainly.in/question/32914246
#SPJ3