In the previous tutorials, we have covered the if statement, if..else statement and if..elif..else statement. In this tutorial, we will learn the nesting of these control statements.
When there is an if statement (or if..else or if..elif..else) is present inside another if statement (or if..else or if..elif..else) then this is calling the nesting of control statements.
Nested if..else statement example
Here we have a if statement inside another if..else statement block. Nesting control statements makes us to check multiple conditions.
num = -99 if num > 0: print("Positive Number") else: print("Negative Number") #nested if if -99<=num: print("Two digit Negative Number")
Output:
Negative Number Two digit Negative Number
Leave a Reply