Overview of if....else Statement

An if statement can be followed by an optional else statement, which executes when the Condition is false.

The if...else statement takes care of true as well as false conditions. It has two blocks. One block is for if and it is executed when the condition is true. The other block is of else  and it is executed when the condition is false.

The else  statement cannot be used without  if. No multiple  else statements are allowed with one if.

Syntax

if expression:
   statement(s)
else:
   statement(s)

Flow Diagram

Flow Diagram of if else statement

 

Example

var1 = 10
if var1:
   print "Hello"
   print var1
else:
   print "Bye"
   print var1

Output

Hello
10