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