Overview of if Statement

An if statement consists of a boolean expression followed by one or more statements. Python uses the keyword if to execute a set of command lines or one command line when logical condition is true. It has only one option. 

An if statement consists of a Boolean expression followed by one or more statements.

If the Boolean expression evaluates to true, then the block of code inside the 'if' statement will be executed.

Syntax

if expression:
   statement(s)

In this statement, if condition is true then statement are execute and if is false, then statement are not execute.

Flow Diagram

Flow Diagram of if statement

 

Example

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

Output:

Hello