Tutorialspoint

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

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


1 Answer
Malhar Lathkar

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
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.