Python Nested If
If Inside If
You can have if
statements inside
if
statements, this is called nested
if
statements.
Example
x = 41
if x> 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
Try it Yourself »
if x> 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
Related Pages
Python If...Else Tutorial If statement If Indentation Elif Else Shorthand If Shorthand If Else If AND If OR If NOT The pass keyword in If