What if we want to execute a different set of operations in case an if condition turns out to be False?
That is where the if-else statement comes into the picture.
Structure
The if-else statement looks something like this:
svg viewer
There’s nothing too tricky going on here. If the condition turns out to be False, the code after the else: keyword is executed.
Hence, we can now perform two different actions based on the condition’s value.
The else keyword will be on the same indentation level as the if keyword. Its body will be indented one tab to the right just like the if statement.
Here’s the if-else statement in action: