Informatics Practices
What is the difference between else and elif constructs of if statement?
Python Control Flow
6 Likes
Answer
The else statement is a default condition that executes when the preceding if and elif (if any) conditions evaluate to False. It does not take any conditions and is written simply as else:, followed by an indented block of code. On the other hand, elif is used to check additional conditions after the initial if statement. If the if condition is False, Python evaluates the elif condition. It is followed by a condition and ends with a colon (:), followed by a block of code.
Answered By
1 Like
Related Questions
Give the output of the following:
print (10 != 9 and 20 >= 20)Give the output of the following:
print(5 % 10 + 10 < 50 and 29 <= 29)Find the output of the following program segment:
for i in range(20, 30, 2): print(i)Find the output of the following program segment:
country = 'INDIA' for i in country: print (i)