Professional Documents
Culture Documents
If Statements
If Statements
condition
True
False
Block of Statement
Exit
if ( (condition1) or (condition2) ):
Statement
Rest of the Code
Indentation
Indentation refers to spaces that are used in the beginning of a statement. By
default python puts 4 spaces but it can be changed by programmers.
if (condition):
____Statement
____if(condition):
________statement 1
________statement 2
____if(condition):
________Statement
if(condition):
____Statement 1
____Statement 2
Rest of the code
If Else Statement
if… else statement is used when a different sequence of instructions is to be executed
depending on the logical value(True/False) of the condition evaluated.
Syntax: - if(condition):
Statement 1
if(condition): Statement 2
Statement 1 else:
else: Statement 3
Statement 2 Statement 4
Rest of the Code Rest of the Code
If
Condition ? False
True
Statement 1 Statement 2
Exit
Condition_2 ? False
True
Condition_3 ? False
True
Statement 1
Condition_n ? False
True
Statement 2
Statement x
True
Statement 3
Statement n
Exit