How to indent multiple if...else statements in Python?


Use of indented blocks is an important feature of Python. Indent level of the block is more than previous statements. Hence, if multiple if statements are present in a program in nested fashion, each subsequent indented block will have increasing level of indent.

if expr1==True:
    if expr2==True:
        stmt1
    else:    
     if expr3==True:
        stmt2
else:
    if expr3==True:
       stmt3
    else:
       stmt4

Updated on: 26-Feb-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements